Class: Hand
- Inherits:
-
Object
- Object
- Hand
- Defined in:
- lib/blackjack/hand.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#blackjack ⇒ Object
Returns the value of attribute blackjack.
-
#cards ⇒ Object
Returns the value of attribute cards.
-
#played ⇒ Object
Returns the value of attribute played.
Instance Method Summary collapse
- #blackjack? ⇒ Boolean
- #busted? ⇒ Boolean
- #deal_card ⇒ Object
-
#initialize(blackjack) ⇒ Hand
constructor
A new instance of Hand.
- #value(count_method, hide_first_card: false) ⇒ Object
Constructor Details
#initialize(blackjack) ⇒ Hand
Returns a new instance of Hand.
6 7 8 9 10 |
# File 'lib/blackjack/hand.rb', line 6 def initialize(blackjack) @blackjack = blackjack @played = false @cards = [] end |
Instance Attribute Details
#blackjack ⇒ Object
Returns the value of attribute blackjack.
4 5 6 |
# File 'lib/blackjack/hand.rb', line 4 def blackjack @blackjack end |
#cards ⇒ Object
Returns the value of attribute cards.
4 5 6 |
# File 'lib/blackjack/hand.rb', line 4 def cards @cards end |
#played ⇒ Object
Returns the value of attribute played.
4 5 6 |
# File 'lib/blackjack/hand.rb', line 4 def played @played end |
Instance Method Details
#blackjack? ⇒ Boolean
20 21 22 |
# File 'lib/blackjack/hand.rb', line 20 def blackjack? cards.size == 2 && value(:soft) == 21 end |
#busted? ⇒ Boolean
12 13 14 |
# File 'lib/blackjack/hand.rb', line 12 def busted? value(:soft) > 21 end |
#deal_card ⇒ Object
16 17 18 |
# File 'lib/blackjack/hand.rb', line 16 def deal_card cards << blackjack.shoe.next_card end |
#value(count_method, hide_first_card: false) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/blackjack/hand.rb', line 24 def value(count_method, hide_first_card: false) total = 0 cards.each_with_index do |card, index| next if index.zero? && hide_first_card total += Card.value(card, count_method, total) end return value(:hard, hide_first_card:) if count_method == :soft && total > 21 total end |