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 (also: #deal!)
-
#initialize(hands = 3, cards = 3) ⇒ Game
constructor
A new instance of Game.
- #inspect ⇒ Object
Constructor Details
Instance Attribute Details
#deck ⇒ Object (readonly)
Returns the value of attribute deck.
6 7 8 |
# File 'lib/deck/game.rb', line 6 def deck @deck end |
#hands ⇒ Object (readonly)
Returns the value of attribute hands.
6 7 8 |
# File 'lib/deck/game.rb', line 6 def hands @hands end |
#number_of_cards ⇒ Object (readonly)
Returns the value of attribute number_of_cards.
6 7 8 |
# File 'lib/deck/game.rb', line 6 def number_of_cards @number_of_cards end |
#number_of_hands ⇒ Object (readonly)
Returns the value of attribute number_of_hands.
6 7 8 |
# File 'lib/deck/game.rb', line 6 def number_of_hands @number_of_hands end |
Instance Method Details
#deal(shuffle = true) ⇒ Object Also known as: deal!
22 23 24 25 26 27 28 29 |
# File 'lib/deck/game.rb', line 22 def deal(shuffle = true) deck.shuffle! if shuffle 1..@hands.size do |n| 1..@number_of_cards.to_i do |m| @hands[m] << deck.draw end end end |
#inspect ⇒ Object
18 19 20 |
# File 'lib/deck/game.rb', line 18 def inspect "#{to_s} with #{@number_of_hands} hands each with #{@number_of_cards} cards" end |