class Rochambeau::Option
Constants
- ALL
- LIZARD
- OUTCOMES
- PAPER
- ROCK
- SCISSORS
- SPOCK
Attributes
initial[R]
name[R]
Public Class Methods
explain(option1, option2)
click to toggle source
# File lib/rochambeau/option.rb, line 104 def explain(option1, option2) unless OUTCOMES[option1] && T.must(OUTCOMES[option1])[option2] raise StandardError, "Unexpected combination: #{option1}, #{option2}" end T.must(T.must(OUTCOMES[option1])[option2])[:explanation] end
from_initial(initial)
click to toggle source
# File lib/rochambeau/option.rb, line 113 def from_initial(initial) result = ALL.detect { |o| o.initial == initial } return result if result raise Rochambeau::InvalidOptionError, "Invalid initial '#{initial}'." end
new(initial, name)
click to toggle source
# File lib/rochambeau/option.rb, line 14 def initialize(initial, name) @initial = initial @name = name end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/rochambeau/option.rb, line 79 def <=>(other) unless OUTCOMES[self] && T.must(OUTCOMES[self])[other] raise StandardError, "Could not compare #{self} with #{other}" end T.must(T.must(OUTCOMES[self])[other])[:result] end
label()
click to toggle source
# File lib/rochambeau/option.rb, line 93 def label "#{@name.capitalize} (#{@initial})" end
to_s()
click to toggle source
# File lib/rochambeau/option.rb, line 88 def to_s @name end