Class: Game
- Inherits:
-
Object
- Object
- Game
- Defined in:
- lib/deck/game.rb
Instance Attribute Summary collapse
-
#deck ⇒ Object
readonly
Returns the value of attribute deck.
-
#hands ⇒ Object
readonly
Returns the value of attribute hands.
-
#number_of_cards ⇒ Object
readonly
Returns the value of attribute number_of_cards.
-
#number_of_hands ⇒ Object
readonly
Returns the value of attribute number_of_hands.
Instance Method Summary collapse
- #deal(shuffle = true) ⇒ Object
-
#initialize(p_hands = 3, p_cards = 3) ⇒ Game
constructor
A new instance of Game.
- #inspect ⇒ Object
Constructor Details
#initialize(p_hands = 3, p_cards = 3) ⇒ Game
Returns a new instance of Game.
6 7 8 9 10 11 12 13 14 |
# File 'lib/deck/game.rb', line 6 def initialize(p_hands = 3, p_cards = 3) @deck = Deck.new @number_of_hands = p_hands @number_of_cards = p_cards @hands = [] @number_of_hands.to_i.times do @hands << Hand.new end end |
Instance Attribute Details
#deck ⇒ Object (readonly)
Returns the value of attribute deck.
3 4 5 |
# File 'lib/deck/game.rb', line 3 def deck @deck end |
#hands ⇒ Object (readonly)
Returns the value of attribute hands.
3 4 5 |
# File 'lib/deck/game.rb', line 3 def hands @hands end |
#number_of_cards ⇒ Object (readonly)
Returns the value of attribute number_of_cards.
3 4 5 |
# File 'lib/deck/game.rb', line 3 def number_of_cards @number_of_cards end |
#number_of_hands ⇒ Object (readonly)
Returns the value of attribute number_of_hands.
3 4 5 |
# File 'lib/deck/game.rb', line 3 def number_of_hands @number_of_hands end |
Instance Method Details
#deal(shuffle = true) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/deck/game.rb', line 20 def deal(shuffle = true) deck.shuffle! if shuffle number_of_cards.times do (1..hands.size).each do |n| hands[n-1] << deck.draw end end self end |
#inspect ⇒ Object
16 17 18 |
# File 'lib/deck/game.rb', line 16 def inspect "#{to_s} with #{@number_of_hands} hands each with #{@number_of_cards} cards" end |