Class: FiftyTwo::Suit

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#colorObject (readonly)

Returns the value of attribute color.



9
10
11
# File 'lib/fiftytwo/suit.rb', line 9

def color
  @color
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/fiftytwo/suit.rb', line 9

def name
  @name
end

#symbolObject (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

#identifierObject



41
42
43
# File 'lib/fiftytwo/suit.rb', line 41

def identifier
  name[0].upcase
end

#to_sObject



37
38
39
# File 'lib/fiftytwo/suit.rb', line 37

def to_s
  name.titleize
end