Class: Tarzan::Games::OddsAndEvens::Move
- Inherits:
-
Object
- Object
- Tarzan::Games::OddsAndEvens::Move
- Defined in:
- lib/tarzan/games/odds_and_evens/move.rb
Instance Attribute Summary collapse
-
#choice ⇒ Object
readonly
Returns the value of attribute choice.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(another) ⇒ Object
-
#initialize(options = {}) ⇒ Move
constructor
A new instance of Move.
- #to_s ⇒ Object
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( = {}) @wins_on_odds = [:wins_on_odds] @choice = [:choice] end |
Instance Attribute Details
#choice ⇒ Object (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
.valid ⇒ Object
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_s ⇒ Object
24 25 26 |
# File 'lib/tarzan/games/odds_and_evens/move.rb', line 24 def to_s "#{@choice}" end |