class RubyHoldem::Deck

Public Class Methods

new() click to toggle source
# File lib/ruby_holdem/deck.rb, line 5
def initialize
  @cards = []
  Card::SUITS.each_byte do |suit|
    # careful not to double include the aces...
    Card::FACES[1..-1].each_byte do |face|
      @cards.push(Card.new(face.chr, suit.chr))
    end
  end
  shuffle
end

Public Instance Methods

burn(burn_cards) click to toggle source

delete an array or a single card from the deck converts a string to a new card, if a string is given

# File lib/ruby_holdem/deck.rb, line 29
def burn(burn_cards)
  return false if burn_cards.is_a?(Integer)
  if burn_cards.is_a?(Card) || burn_cards.is_a?(String)
    burn_cards = [burn_cards]
  end

  burn_cards.map! do |c|
    c = Card.new(c) unless c.class == Card
    @cards.delete(c)
  end
  true
end
deal() click to toggle source

removes a single card from the top of the deck and returns it synonymous to poping off a stack

# File lib/ruby_holdem/deck.rb, line 23
def deal
  @cards.pop
end
empty?() click to toggle source
# File lib/ruby_holdem/deck.rb, line 47
def empty?
  @cards.empty?
end
shuffle() click to toggle source
# File lib/ruby_holdem/deck.rb, line 16
def shuffle
  @cards = @cards.sort_by { rand }
  return self
end
size() click to toggle source

return count of the remaining cards

# File lib/ruby_holdem/deck.rb, line 43
def size
  @cards.size
end