Class: Deck
- Inherits:
-
Object
- Object
- Deck
- Defined in:
- lib/deck.rb
Instance Attribute Summary collapse
-
#cards ⇒ Object
readonly
Returns the value of attribute cards.
Instance Method Summary collapse
- #create_standard_deck ⇒ Object
-
#initialize ⇒ Deck
constructor
A new instance of Deck.
Constructor Details
#initialize ⇒ Deck
Returns a new instance of Deck.
4 5 6 7 |
# File 'lib/deck.rb', line 4 def initialize @cards = [] create_standard_deck end |
Instance Attribute Details
#cards ⇒ Object (readonly)
Returns the value of attribute cards.
2 3 4 |
# File 'lib/deck.rb', line 2 def cards @cards end |
Instance Method Details
#create_standard_deck ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/deck.rb', line 9 def create_standard_deck card_values = {'2' => 2,'3' => 3,'4' => 4,'5' => 5,'6' => 6,'7' => 7,'8' => 8, '9' => 9,'10' => 10,'J' => 10,'Q' => 10,'K' => 10, 'A' => 11} suits = ['S', 'D', 'C', 'H'] suits.each do |suit| card_values.each do |rank, value| card = Card.new(rank, value, suit) @cards.push(card) end end end |