Class: RubyHoldem::Deck
- Inherits:
-
Object
- Object
- RubyHoldem::Deck
- Defined in:
- lib/ruby_holdem/deck.rb
Instance Method Summary collapse
-
#burn(burn_cards) ⇒ Object
delete an array or a single card from the deck converts a string to a new card, if a string is given.
-
#deal ⇒ Object
removes a single card from the top of the deck and returns it synonymous to poping off a stack.
- #empty? ⇒ Boolean
-
#initialize ⇒ Deck
constructor
A new instance of Deck.
- #shuffle ⇒ Object
-
#size ⇒ Object
return count of the remaining cards.
Constructor Details
#initialize ⇒ Deck
Returns a new instance of Deck.
5 6 7 8 9 10 11 12 13 14 |
# 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 |
Instance Method Details
#burn(burn_cards) ⇒ Object
delete an array or a single card from the deck converts a string to a new card, if a string is given
29 30 31 32 33 34 35 36 37 38 39 40 |
# 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 ⇒ Object
removes a single card from the top of the deck and returns it synonymous to poping off a stack
23 24 25 |
# File 'lib/ruby_holdem/deck.rb', line 23 def deal @cards.pop end |
#empty? ⇒ Boolean
47 48 49 |
# File 'lib/ruby_holdem/deck.rb', line 47 def empty? @cards.empty? end |
#shuffle ⇒ Object
16 17 18 19 |
# File 'lib/ruby_holdem/deck.rb', line 16 def shuffle @cards = @cards.sort_by { rand } return self end |
#size ⇒ Object
return count of the remaining cards
43 44 45 |
# File 'lib/ruby_holdem/deck.rb', line 43 def size @cards.size end |