Class: FiftyTwo::Suit
- Inherits:
-
Object
- Object
- FiftyTwo::Suit
- Includes:
- Comparable
- Defined in:
- lib/fiftytwo/suit.rb,
lib/fiftytwo/suit/color.rb
Defined Under Namespace
Classes: Color
Constant Summary collapse
- ALL =
[ CLUBS = Suit.new("clubs", Color::BLACK, "♣").freeze, DIAMONDS = Suit.new("diamonds", Color::RED, "♦").freeze, HEARTS = Suit.new("hearts", Color::RED, "♥").freeze, SPADES = Suit.new("spades", Color::BLACK, "♠").freeze ]
Instance Attribute Summary collapse
-
#color ⇒ Object
readonly
Returns the value of attribute color.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#symbol ⇒ Object
(also: #code)
readonly
Returns the value of attribute symbol.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #identifier ⇒ Object
-
#initialize(name, color, symbol = nil) ⇒ Suit
constructor
A new instance of Suit.
- #to_s ⇒ Object
Constructor Details
#initialize(name, color, symbol = nil) ⇒ Suit
Returns a new instance of Suit.
12 13 14 15 16 |
# File 'lib/fiftytwo/suit.rb', line 12 def initialize(name, color, symbol = nil) @name = name @color = color @symbol = symbol end |
Instance Attribute Details
#color ⇒ Object (readonly)
Returns the value of attribute color.
9 10 11 |
# File 'lib/fiftytwo/suit.rb', line 9 def color @color end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/fiftytwo/suit.rb', line 9 def name @name end |
#symbol ⇒ Object (readonly) Also known as: code
Returns the value of attribute symbol.
9 10 11 |
# File 'lib/fiftytwo/suit.rb', line 9 def symbol @symbol end |
Instance Method Details
#<=>(other) ⇒ Object
33 34 35 |
# File 'lib/fiftytwo/suit.rb', line 33 def <=>(other) name <=> other.name end |
#identifier ⇒ Object
41 42 43 |
# File 'lib/fiftytwo/suit.rb', line 41 def identifier name[0].upcase end |
#to_s ⇒ Object
37 38 39 |
# File 'lib/fiftytwo/suit.rb', line 37 def to_s name.titleize end |