Class: Ventiuna::Card
- Inherits:
-
Object
- Object
- Ventiuna::Card
- Defined in:
- lib/ventiuna/card.rb
Instance Attribute Summary collapse
-
#rank ⇒ Object
Returns the value of attribute rank.
-
#suit ⇒ Object
Returns the value of attribute suit.
Instance Method Summary collapse
-
#<=>(other_card) ⇒ Object
sorts cards with Aces always high.
- #==(other_card) ⇒ Object
- #ace? ⇒ Boolean
-
#initialize(rank: "joker", suit: "joker") ⇒ Card
constructor
A new instance of Card.
- #to_i(high: true, low: false) ⇒ Object (also: #value)
- #to_s ⇒ Object
Constructor Details
#initialize(rank: "joker", suit: "joker") ⇒ Card
Returns a new instance of Card.
5 6 7 8 |
# File 'lib/ventiuna/card.rb', line 5 def initialize(rank: "joker", suit: "joker") @rank = rank.to_s.upcase @suit = suit end |
Instance Attribute Details
#rank ⇒ Object
Returns the value of attribute rank.
3 4 5 |
# File 'lib/ventiuna/card.rb', line 3 def rank @rank end |
#suit ⇒ Object
Returns the value of attribute suit.
3 4 5 |
# File 'lib/ventiuna/card.rb', line 3 def suit @suit end |
Instance Method Details
#<=>(other_card) ⇒ Object
sorts cards with Aces always high
23 24 25 |
# File 'lib/ventiuna/card.rb', line 23 def <=>(other_card) self.value(high: true) <=> other_card.value(high: true) end |
#==(other_card) ⇒ Object
27 28 29 |
# File 'lib/ventiuna/card.rb', line 27 def ==(other_card) self.to_s == other_card.to_s end |
#ace? ⇒ Boolean
18 19 20 |
# File 'lib/ventiuna/card.rb', line 18 def ace? self.rank == "A" end |
#to_i(high: true, low: false) ⇒ Object Also known as: value
10 11 12 13 14 15 |
# File 'lib/ventiuna/card.rb', line 10 def to_i(high: true, low: false) return 1 if self.ace? && low return 11 if self.ace? && high return 10 if ["K", "Q", "J"].include?(self.rank) self.rank.to_i end |
#to_s ⇒ Object
31 32 33 |
# File 'lib/ventiuna/card.rb', line 31 def to_s "#{self.rank} #{self.suit}" end |