Class: Suit
Overview
The four categories in a deck of cards.
Each card bears one of four symbols showing which suit it belongs to. A deck of cards has four suits: hearts, clubs, spades, and diamonds.
Constant Summary collapse
- HEART =
new(2, "H", "Heart", 1)
- DIAMOND =
new(3, "D", "Diamond", 2)
- SPADE =
new(5, "S", "Spade", 3)
- CLUB =
new(7, "C", "Club", 4)
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#order ⇒ Object
readonly
Returns the value of attribute order.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(suit) ⇒ Object
- #==(suit) ⇒ Object
- #eql?(suit) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(id, key, value, order) ⇒ Suit
constructor
A new instance of Suit.
- #to_s ⇒ Object
Constructor Details
#initialize(id, key, value, order) ⇒ Suit
Returns a new instance of Suit.
12 13 14 15 16 17 |
# File 'lib/rora/model/suit.rb', line 12 def initialize(id, key, value, order) @id = id @key = key @value = value @order = order end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
10 11 12 |
# File 'lib/rora/model/suit.rb', line 10 def id @id end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
10 11 12 |
# File 'lib/rora/model/suit.rb', line 10 def key @key end |
#order ⇒ Object (readonly)
Returns the value of attribute order.
10 11 12 |
# File 'lib/rora/model/suit.rb', line 10 def order @order end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
10 11 12 |
# File 'lib/rora/model/suit.rb', line 10 def value @value end |
Class Method Details
.get(key) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/rora/model/suit.rb', line 23 def self.get(key) self.values.each do |suit| return suit if suit.key.casecmp(key) == 0 end raise ArgumentError, "No suit exists for key '#{key}'" end |
Instance Method Details
#<=>(suit) ⇒ Object
30 31 32 |
# File 'lib/rora/model/suit.rb', line 30 def <=>(suit) self.order <=> suit.order end |
#==(suit) ⇒ Object
38 39 40 |
# File 'lib/rora/model/suit.rb', line 38 def == suit self.key == suit.key end |
#eql?(suit) ⇒ Boolean
34 35 36 |
# File 'lib/rora/model/suit.rb', line 34 def eql? suit self == suit end |
#hash ⇒ Object
42 43 44 |
# File 'lib/rora/model/suit.rb', line 42 def hash return self.key.ord end |
#to_s ⇒ Object
46 47 48 |
# File 'lib/rora/model/suit.rb', line 46 def to_s "#{@value}s" end |