Class: Blackjack::Hand

Inherits:
Object
  • Object
show all
Defined in:
lib/blackjack/hand.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cards = []) ⇒ Hand

Returns a new instance of Hand.



4
5
6
# File 'lib/blackjack/hand.rb', line 4

def initialize(cards = [])
  @cards = cards
end

Instance Attribute Details

#cardsObject (readonly)

Returns the value of attribute cards.



3
4
5
# File 'lib/blackjack/hand.rb', line 3

def cards
  @cards
end

Instance Method Details

#account_for_aces(value) ⇒ Object



13
14
15
# File 'lib/blackjack/hand.rb', line 13

def (value)
  value < 12 && contains_ace? ? value + 10 : value
end

#bust?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/blackjack/hand.rb', line 21

def bust?
  cards_value > 21
end

#cards_valueObject



8
9
10
11
# File 'lib/blackjack/hand.rb', line 8

def cards_value
  value = cards.inject(0) { |sum, card| sum + card.value }
  (value)
end

#contains_ace?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/blackjack/hand.rb', line 17

def contains_ace?
  cards.any? { |card| card.is_ace? }
end