Class: Holdem::Deck
- Inherits:
-
Object
- Object
- Holdem::Deck
- Defined in:
- lib/deck.rb
Instance Attribute Summary collapse
-
#cards ⇒ Object
readonly
Returns the value of attribute cards.
Instance Method Summary collapse
- #deal ⇒ Object
-
#initialize(shuffle_cards = true) ⇒ Deck
constructor
A new instance of Deck.
- #remove(card) ⇒ Object
- #shuffle ⇒ Object
Constructor Details
#initialize(shuffle_cards = true) ⇒ Deck
Returns a new instance of Deck.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/deck.rb', line 11 def initialize(shuffle_cards=true) @cards = [] Card::SUITS.each_byte do |suit| Card::RANKS.each_byte do |rank| @cards << Card.new(rank.chr + suit.chr) end end shuffle if shuffle_cards end |
Instance Attribute Details
#cards ⇒ Object (readonly)
Returns the value of attribute cards.
5 6 7 |
# File 'lib/deck.rb', line 5 def cards @cards end |
Instance Method Details
#deal ⇒ Object
22 23 24 |
# File 'lib/deck.rb', line 22 def deal @cards.pop end |
#remove(card) ⇒ Object
26 27 28 |
# File 'lib/deck.rb', line 26 def remove(card) @cards.delete_at(@cards.index(card)) end |
#shuffle ⇒ Object
7 8 9 |
# File 'lib/deck.rb', line 7 def shuffle @cards = @cards.sort_by { rand } end |