Class: RubyCards::Deck
- Inherits:
-
Object
- Object
- RubyCards::Deck
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/rubycards/deck.rb
Constant Summary collapse
- RANKS =
[*2..10, 'Jack', 'Queen', 'King', 'Ace']
- SUITS =
%w{ Clubs Diamonds Hearts Spades }
Instance Attribute Summary collapse
-
#cards ⇒ Object
readonly
Returns the value of attribute cards.
Instance Method Summary collapse
-
#each(&block) ⇒ Enumerable
Enumerates the deck.
-
#initialize ⇒ Deck
constructor
Initializes a standard deck of 52 cards.
-
#inspect ⇒ String
Displays a shortened version of the #to_s method for use in the ruby console.
-
#shuffle! ⇒ Deck
Shuffles the deck and returns it.
-
#to_s ⇒ String
Displays concise card representations in an array.
Constructor Details
Instance Attribute Details
#cards ⇒ Object (readonly)
Returns the value of attribute cards.
9 10 11 |
# File 'lib/rubycards/deck.rb', line 9 def cards @cards end |
Instance Method Details
#each(&block) ⇒ Enumerable
Enumerates the deck
41 42 43 |
# File 'lib/rubycards/deck.rb', line 41 def each(&block) @cards.each(&block) end |
#inspect ⇒ String
Displays a shortened version of the #to_s method for use in the ruby console
56 57 58 |
# File 'lib/rubycards/deck.rb', line 56 def inspect "[ #{@cards[0..2].map(&:inspect).join ', '}, ..., #{@cards[-3..-1].map(&:inspect).join ', '} ]" end |
#shuffle! ⇒ Deck
Shuffles the deck and returns it
32 33 34 35 |
# File 'lib/rubycards/deck.rb', line 32 def shuffle! @cards.shuffle! self end |
#to_s ⇒ String
Displays concise card representations in an array
48 49 50 |
# File 'lib/rubycards/deck.rb', line 48 def to_s "[ #{@cards.map(&:inspect).join ', '} ]" end |