Sha256: afa7bdd032dfc7a61e185946261af1d567a33b96fb88a10552aa0af653d8beed
Contents?: true
Size: 724 Bytes
Versions: 1
Compression:
Stored size: 724 Bytes
Contents
class Deck include Enumerable attr_reader :cards RANKS = [*2..10, 'Jack', 'Queen', 'King', 'Ace'] SUITS = %w{ Clubs Diamonds Hearts Spades } # initialize a deck of cards using the RANKS and SUITS constants def initialize @cards = [] RANKS.product(SUITS).each do |rank, suit| @cards << Card.new(rank, suit) end end # shuffle the deck def shuffle! @cards.shuffle! end # draw a card from the deck def draw @cards.shift end # determines if the deck is empty def empty? @cards.empty? end # Enumerable#each def each(&block) @cards.each do |card| if block_given? block.call card else yield card end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rubycards-0.0.1 | lib/rubycards/deck.rb |