Class: CardNine::Cards::PlayingCard
- Inherits:
-
Object
- Object
- CardNine::Cards::PlayingCard
- Includes:
- CardNine::Card, Comparable
- Defined in:
- lib/card_nine/cards/playing_card.rb
Overview
A class that represents the typical playing card from a 52 card deck.
Constant Summary collapse
- SUITS =
ALL Suits of cards
%w|Clubs Hearts Diamonds Spades|.freeze
- RANKS =
All Ranks of cards
%w|2 3 4 5 6 7 8 9 10 Jack Queen King Ace|.freeze
Instance Attribute Summary collapse
-
#rank ⇒ String
Rank of card.
-
#suit ⇒ String
Suit of card.
Attributes included from CardNine::Card
Class Method Summary collapse
-
.deck(rng = Random.new) ⇒ Object
create and return a standard 52 card deck of playing cards.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
implement sort based on rank of the card, 2 low ace high.
Instance Attribute Details
#rank ⇒ String
Returns rank of card.
26 |
# File 'lib/card_nine/cards/playing_card.rb', line 26 attribute :rank, String |
#suit ⇒ String
Returns suit of card.
23 |
# File 'lib/card_nine/cards/playing_card.rb', line 23 attribute :suit, String |
Class Method Details
.deck(rng = Random.new) ⇒ Object
create and return a standard 52 card deck of playing cards
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/card_nine/cards/playing_card.rb', line 34 def self.deck(rng = Random.new) all = [] SUITS.each do |suit| RANKS.each do |rank| id = rank.to_i > 0 ? rank : rank[0] id += suit[0] all << { rank: rank, suit: suit, id: id, name: "#{rank} of #{suit}" } end end Deck.new(cards: all.map { |c| self.new(c) }, rng: rng) end |