Class: Tarzan::Games::OddsAndEvens::Move

Inherits:
Object
  • Object
show all
Defined in:
lib/tarzan/games/odds_and_evens/move.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Move

Returns a new instance of Move.



11
12
13
14
# 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

Instance Attribute Details

#choiceObject (readonly)

Returns the value of attribute choice.



5
6
7
# File 'lib/tarzan/games/odds_and_evens/move.rb', line 5

def choice
  @choice
end

Class Method Details

.validObject



7
8
9
# File 'lib/tarzan/games/odds_and_evens/move.rb', line 7

def self.valid
  ('1'..'5').to_a
end

Instance Method Details

#<=>(another) ⇒ Object



16
17
18
19
20
21
22
# 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_sObject



24
25
26
# File 'lib/tarzan/games/odds_and_evens/move.rb', line 24

def to_s
  "#{@choice}"
end