Class: PokerEngine::Card
- Inherits:
-
Object
- Object
- PokerEngine::Card
- Defined in:
- lib/poker_engine/card.rb
Constant Summary collapse
- COLORS =
{ spade: :spade, club: :club, heart: :heart, diamond: :diamond }.freeze
- RANKS =
(2..10).to_a.map(&:to_s) + %w(J Q K A)
Instance Attribute Summary collapse
-
#color ⇒ Object
readonly
Returns the value of attribute color.
-
#rank ⇒ Object
readonly
Returns the value of attribute rank.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(rank, color) ⇒ Card
constructor
A new instance of Card.
- #to_s ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(rank, color) ⇒ Card
Returns a new instance of Card.
14 15 16 17 |
# File 'lib/poker_engine/card.rb', line 14 def initialize(rank, color) @rank = rank @color = color end |
Instance Attribute Details
#color ⇒ Object (readonly)
Returns the value of attribute color.
12 13 14 |
# File 'lib/poker_engine/card.rb', line 12 def color @color end |
#rank ⇒ Object (readonly)
Returns the value of attribute rank.
12 13 14 |
# File 'lib/poker_engine/card.rb', line 12 def rank @rank end |
Class Method Details
.french_deck ⇒ Object
6 7 8 9 10 |
# File 'lib/poker_engine/card.rb', line 6 def self.french_deck Card::RANKS .product(Card::COLORS.values) .map { |rank, color| Card.new rank, color } end |
Instance Method Details
#to_s ⇒ Object
23 24 25 |
# File 'lib/poker_engine/card.rb', line 23 def to_s "#{@rank}#{@color[0]}" end |
#value ⇒ Object
19 20 21 |
# File 'lib/poker_engine/card.rb', line 19 def value @value ||= RANKS.index rank end |