Class: Card
Instance Attribute Summary collapse
-
#rank ⇒ Object
readonly
Returns the value of attribute rank.
-
#suit ⇒ Object
readonly
Returns the value of attribute suit.
Instance Method Summary collapse
- #<(other) ⇒ Object
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
- #>(other) ⇒ Object
- #each ⇒ Object
-
#initialize(rank = 'Joker', suit = 'None') ⇒ Card
constructor
A new instance of Card.
- #inspect ⇒ Object
- #to_i ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(rank = 'Joker', suit = 'None') ⇒ Card
Returns a new instance of Card.
9 10 11 12 |
# File 'lib/deck/card.rb', line 9 def initialize(rank = 'Joker', suit = 'None') @suit = suit @rank = rank end |
Instance Attribute Details
#rank ⇒ Object (readonly)
Returns the value of attribute rank.
7 8 9 |
# File 'lib/deck/card.rb', line 7 def rank @rank end |
#suit ⇒ Object (readonly)
Returns the value of attribute suit.
7 8 9 |
# File 'lib/deck/card.rb', line 7 def suit @suit end |
Instance Method Details
#<(other) ⇒ Object
46 47 48 |
# File 'lib/deck/card.rb', line 46 def <(other) to_i<other.to_i end |
#<=>(other) ⇒ Object
42 43 44 |
# File 'lib/deck/card.rb', line 42 def <=>(other) to_i<=>other.to_i end |
#==(other) ⇒ Object
38 39 40 |
# File 'lib/deck/card.rb', line 38 def ==(other) to_i == other.to_i && suit == other.suit end |
#>(other) ⇒ Object
50 51 52 |
# File 'lib/deck/card.rb', line 50 def >(other) to_i>other.to_i end |
#each ⇒ Object
54 55 56 |
# File 'lib/deck/card.rb', line 54 def each yield end |
#inspect ⇒ Object
26 27 28 |
# File 'lib/deck/card.rb', line 26 def inspect to_s end |
#to_i ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/deck/card.rb', line 58 def to_i case @rank.to_s.upcase[0..1] when 'JA' 11 when 'QU' 12 when 'KI' 13 when 'AC' 14 when 'JO' 15 else @rank.to_i end end |
#to_s ⇒ Object
34 35 36 |
# File 'lib/deck/card.rb', line 34 def to_s "#{rank} of #{suit}" end |