class Tarzan::Games::OddsAndEvens::Move

Attributes

choice[R]

Public Class Methods

new(options = {}) click to toggle source
# File lib/tarzan/games/odds_and_evens/move.rb, line 11
def initialize(options = {})
  @wins_on_odds = options[:wins_on_odds]
  @choice = options[:choice]
end
valid() click to toggle source
# File lib/tarzan/games/odds_and_evens/move.rb, line 7
def self.valid
  ('1'..'5').to_a
end

Public Instance Methods

<=>(another) click to toggle source
# File lib/tarzan/games/odds_and_evens/move.rb, line 16
def <=>(another)
  case choice.to_i + another.choice.to_i + finger_offset
    when ->(sum) { sum.odd? } then 1
    when ->(sum) { sum.even? } then -1
    else 0 # impossible :)
  end
end
to_s() click to toggle source
# File lib/tarzan/games/odds_and_evens/move.rb, line 24
def to_s
  "#{@choice}"
end

Private Instance Methods

finger_offset() click to toggle source
# File lib/tarzan/games/odds_and_evens/move.rb, line 30
def finger_offset
  @wins_on_odds ? 0 : 1
end