class RubyCards::Deck

Constants

RANKS
SUITS

Attributes

cards[R]

Public Class Methods

new() click to toggle source

Initializes a standard deck of 52 cards

@return [Deck] A standard deck of cards

# File lib/rubycards/deck.rb, line 21
def initialize
  @cards = []

  RANKS.product(SUITS).each do |rank, suit|
    @cards << Card.new(rank, suit)
  end
end

Public Instance Methods

each(&block) click to toggle source

Enumerates the deck

@param block [Proc] The block to pass into the enumerator @return [Enumerable] The deck enumerator

# File lib/rubycards/deck.rb, line 41
def each(&block)
  @cards.each(&block)
end
inspect() click to toggle source

Displays a shortened version of the to_s method for use in the ruby console

@return [String] A shortened string output of the deck

# File lib/rubycards/deck.rb, line 56
def inspect
  "[ #{@cards[0..2].map(&:inspect).join ', '}, ..., #{@cards[-3..-1].map(&:inspect).join ', '} ]"
end
shuffle!() click to toggle source

Shuffles the deck and returns it

@return [Deck] The shuffled deck

# File lib/rubycards/deck.rb, line 32
def shuffle!
  @cards.shuffle!
  self
end
to_s() click to toggle source

Displays concise card representations in an array

@return [String] The concise string representation of the deck

# File lib/rubycards/deck.rb, line 48
def to_s
  "[ #{@cards.map(&:inspect).join ', '} ]"
end