Class: Card
- Inherits:
-
Object
- Object
- Card
- Defined in:
- lib/playing_cards/card.rb
Instance Attribute Summary collapse
-
#rank ⇒ Object
Returns the value of attribute rank.
-
#suit ⇒ Object
Returns the value of attribute suit.
Class Method Summary collapse
- .parse(name) ⇒ Object (also: [])
Instance Method Summary collapse
- #<(another_card) ⇒ Object
- #==(another_card) ⇒ Object
- #>(another_card) ⇒ Object
- #equals?(another_card) ⇒ Boolean
-
#initialize(rank, suit) ⇒ Card
constructor
A new instance of Card.
- #inspect ⇒ Object
- #name ⇒ Object (also: #to_s)
- #numberify ⇒ Object
Constructor Details
#initialize(rank, suit) ⇒ Card
Returns a new instance of Card.
4 5 6 7 |
# File 'lib/playing_cards/card.rb', line 4 def initialize rank, suit @rank = rank.to_s.capitalize @suit = suit.downcase.sub(/s$/,'').capitalize end |
Instance Attribute Details
#rank ⇒ Object
Returns the value of attribute rank.
2 3 4 |
# File 'lib/playing_cards/card.rb', line 2 def rank @rank end |
#suit ⇒ Object
Returns the value of attribute suit.
2 3 4 |
# File 'lib/playing_cards/card.rb', line 2 def suit @suit end |
Class Method Details
Instance Method Details
#<(another_card) ⇒ Object
17 18 19 |
# File 'lib/playing_cards/card.rb', line 17 def < another_card numberify < another_card.numberify end |
#==(another_card) ⇒ Object
9 10 11 |
# File 'lib/playing_cards/card.rb', line 9 def == another_card rank == another_card.rank && suit == another_card.suit end |
#>(another_card) ⇒ Object
13 14 15 |
# File 'lib/playing_cards/card.rb', line 13 def > another_card numberify > another_card.numberify end |
#equals?(another_card) ⇒ Boolean
21 22 23 |
# File 'lib/playing_cards/card.rb', line 21 def equals? another_card numberify == another_card.numberify end |
#inspect ⇒ Object
57 58 59 |
# File 'lib/playing_cards/card.rb', line 57 def inspect "<Card: \"#{ name }\">" end |
#name ⇒ Object Also known as: to_s
53 54 55 |
# File 'lib/playing_cards/card.rb', line 53 def name "#{ rank } of #{ suit }s" end |
#numberify ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/playing_cards/card.rb', line 25 def numberify convert = { 'Two' => 2, 'Three' => 3, 'Four' => 4, 'Five' => 5, 'Six' => 6, 'Seven' => 7, 'Eight' => 8, 'Nine' => 9, 'Ten' => 10, 'Jack' => 11, 'Queen' => 12, 'King' => 13, 'Ace' => 14, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, '10' => 10 } convert[rank] end |