Class: Tarzan::Games::RockPaperScissors::Move

Inherits:
Object
  • Object
show all
Defined in:
lib/tarzan/games/rock_paper_scissors/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
# File 'lib/tarzan/games/rock_paper_scissors/move.rb', line 11

def initialize(options = {})
  @choice = options[:choice]
end

Instance Attribute Details

#choiceObject (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

.validObject



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_sObject



23
24
25
# File 'lib/tarzan/games/rock_paper_scissors/move.rb', line 23

def to_s
  "#{@choice}"
end