Class: Deck
- Inherits:
-
Object
- Object
- Deck
- Defined in:
- lib/mblackjack/deck.rb
Instance Attribute Summary collapse
-
#ace ⇒ Object
Returns the value of attribute ace.
-
#cards ⇒ Object
Returns the value of attribute cards.
-
#unique_cards ⇒ Object
Returns the value of attribute unique_cards.
Class Method Summary collapse
Instance Method Summary collapse
- #assign_value ⇒ Object
-
#initialize ⇒ Deck
constructor
A new instance of Deck.
- #make_deck ⇒ Object
Constructor Details
#initialize ⇒ Deck
Returns a new instance of Deck.
4 5 6 7 8 9 10 11 12 |
# File 'lib/mblackjack/deck.rb', line 4 def initialize @unique_cards = ['ace',2,3,4,5,6,7,8,9,10,'J','Q','K'] @cards = [] @@card_values = {} make_deck assign_value end |
Instance Attribute Details
#ace ⇒ Object
Returns the value of attribute ace.
2 3 4 |
# File 'lib/mblackjack/deck.rb', line 2 def ace @ace end |
#cards ⇒ Object
Returns the value of attribute cards.
2 3 4 |
# File 'lib/mblackjack/deck.rb', line 2 def cards @cards end |
#unique_cards ⇒ Object
Returns the value of attribute unique_cards.
2 3 4 |
# File 'lib/mblackjack/deck.rb', line 2 def unique_cards @unique_cards end |
Class Method Details
.card_values ⇒ Object
20 21 22 |
# File 'lib/mblackjack/deck.rb', line 20 def self.card_values @@card_values end |
Instance Method Details
#assign_value ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/mblackjack/deck.rb', line 24 def assign_value v = 1 unique_cards.each do |c| @@card_values.store(c, v) v += 1 end @@card_values['ace'] = [1,11] @@card_values['J'] = 10 @@card_values['Q'] = 10 @@card_values['K'] = 10 end |
#make_deck ⇒ Object
14 15 16 17 18 |
# File 'lib/mblackjack/deck.rb', line 14 def make_deck @cards = [] @cards << unique_cards * 4 @cards = @cards.flatten end |