Class: TexasHoldem::Player
Instance Attribute Summary collapse
-
#cards ⇒ Object
readonly
Returns the value of attribute cards.
-
#cash ⇒ Object
readonly
Returns the value of attribute cash.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #bet(amount) ⇒ Object
- #check ⇒ Object
- #fold ⇒ Object
-
#initialize(name, cash) ⇒ Player
constructor
A new instance of Player.
- #take_winnings(amount) ⇒ Object
Constructor Details
#initialize(name, cash) ⇒ Player
Returns a new instance of Player.
10 11 12 13 |
# File 'lib/player.rb', line 10 def initialize(name,cash) @name, @cash = name, cash @cards = [] end |
Instance Attribute Details
#cards ⇒ Object (readonly)
Returns the value of attribute cards.
7 8 9 |
# File 'lib/player.rb', line 7 def cards @cards end |
#cash ⇒ Object (readonly)
Returns the value of attribute cash.
7 8 9 |
# File 'lib/player.rb', line 7 def cash @cash end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/player.rb', line 7 def name @name end |
Instance Method Details
#bet(amount) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/player.rb', line 15 def bet(amount) # TODO: add remaining cash instead of raising an error raise NotEnoughCashError unless enough_cash_for?(amount) @cash -= amount changed true notify_observers :bet => { :player => self, :amount => amount } amount end |
#check ⇒ Object
24 25 26 |
# File 'lib/player.rb', line 24 def check bet 0 end |
#fold ⇒ Object
28 29 30 31 |
# File 'lib/player.rb', line 28 def fold changed true notify_observers :fold => true end |
#take_winnings(amount) ⇒ Object
33 34 35 |
# File 'lib/player.rb', line 33 def take_winnings(amount) @cash += amount end |