Module: Colorful

Included in:
CardObject, RouteObject
Defined in:
lib/ttr/objects/colorful.rb

Overview

Copyright © 2011 Jesse Sielaff

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#colorObject (readonly)

Returns the value of attribute color.



7
8
9
# File 'lib/ttr/objects/colorful.rb', line 7

def color
  @color
end

Instance Method Details

#exact_match?(c) ⇒ Boolean

Returns true if the given Symbol or Colorful object represents the exact same color as the receiver, false otherwise. Returns nil if the given object is neither a Symbol nor Colorful.

Returns:

  • (Boolean)


13
14
15
16
17
18
# File 'lib/ttr/objects/colorful.rb', line 13

def exact_match? (c)
  case c
    when Symbol then @color == c
    when Colorful then exact_match? c.color
  end
end

#match?(c) ⇒ Boolean

Returns true if the given Symbol or Colorful object represents a color match with the receiver, false otherwise. The colors :wild and :grey match every color. Returns nil if the given object is neither a Symbol nor Colorful.

Returns:

  • (Boolean)


24
25
26
27
28
29
# File 'lib/ttr/objects/colorful.rb', line 24

def match? (c)
  case c
    when Symbol then [:grey, :wild, @color].include? c
    when Colorful then match? c.color
  end
end