Class: TwentyOne::Hand

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cards = []) ⇒ Hand

Returns a new instance of Hand.



7
8
9
# File 'lib/twenty_one/hand.rb', line 7

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

Instance Attribute Details

#cardsObject (readonly)

Returns the value of attribute cards.



5
6
7
# File 'lib/twenty_one/hand.rb', line 5

def cards
  @cards
end

Instance Method Details

#clearObject



11
12
13
# File 'lib/twenty_one/hand.rb', line 11

def clear
  @cards = []
end

#valueObject



15
16
17
18
19
20
21
22
23
# File 'lib/twenty_one/hand.rb', line 15

def value
  count = 0

  @cards.each do |card|
    count += card.value
  end

  count
end