Class: Tarzan::Games::RockPaperScissors::Move
- Inherits:
-
Object
- Object
- Tarzan::Games::RockPaperScissors::Move
- Defined in:
- lib/tarzan/games/rock_paper_scissors/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 |
# File 'lib/tarzan/games/rock_paper_scissors/move.rb', line 11 def initialize( = {}) @choice = [:choice] end |
Instance Attribute Details
#choice ⇒ Object (readonly)
Returns the value of attribute choice.
5 6 7 |
# File 'lib/tarzan/games/rock_paper_scissors/move.rb', line 5 def choice @choice end |
Class Method Details
.valid ⇒ Object
7 8 9 |
# File 'lib/tarzan/games/rock_paper_scissors/move.rb', line 7 def self.valid ['R', 'P', 'S'] end |
Instance Method Details
#<=>(another) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/tarzan/games/rock_paper_scissors/move.rb', line 15 def <=>(another) case "#{choice}#{another.choice}" when 'RS', 'SP', 'PR' then 1 when 'RP', 'SR', 'PS' then -1 else 0 end end |
#to_s ⇒ Object
23 24 25 |
# File 'lib/tarzan/games/rock_paper_scissors/move.rb', line 23 def to_s "#{@choice}" end |