Class: Patience::Card::Rank
Overview
Rank class provides underlying methods for every rank.
Instance Method Summary collapse
-
#<=>(other_rank) ⇒ Object
Compares two ranks with each other.
- #ace? ⇒ Boolean
- #higher_by_one_than?(other_rank) ⇒ Boolean
- #king? ⇒ Boolean
- #queen? ⇒ Boolean
-
#to_s ⇒ Object
Returns string representation of a rank.
Instance Method Details
#<=>(other_rank) ⇒ Object
Compares two ranks with each other. Based on integer values.
38 39 40 |
# File 'lib/patience/rank.rb', line 38 def <=>(other_rank) @num <=> other_rank.to_i end |
#ace? ⇒ Boolean
42 |
# File 'lib/patience/rank.rb', line 42 def ace?; @num == 1; end |
#higher_by_one_than?(other_rank) ⇒ Boolean
46 47 48 |
# File 'lib/patience/rank.rb', line 46 def higher_by_one_than?(other_rank) @num - other_rank.to_i == 1 end |
#king? ⇒ Boolean
43 |
# File 'lib/patience/rank.rb', line 43 def king?; @num == 13; end |
#queen? ⇒ Boolean
44 |
# File 'lib/patience/rank.rb', line 44 def queen?; @num == 12; end |
#to_s ⇒ Object
Returns string representation of a rank. It asks class to give its full name, exscinding everything but its actual name.
33 34 35 |
# File 'lib/patience/rank.rb', line 33 def to_s "#{self.class.name.demodulize}" end |