Class: AngryRock::Internal::AngryRock

Inherits:
Object
  • Object
show all
Defined in:
lib/angryrock/play.rb

Overview

This is implementation details. Not for client use. Don’t touch me.

Constant Summary collapse

WINS =
{rock: :scissors, scissors: :paper, paper: :rock}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(move) ⇒ AngryRock

Returns a new instance of AngryRock.



26
27
28
# File 'lib/angryrock/play.rb', line 26

def initialize(move)
  @move = move
end

Instance Attribute Details

#moveObject

Returns the value of attribute move.



24
25
26
# File 'lib/angryrock/play.rb', line 24

def move
  @move
end

Instance Method Details

#has_winner?(opponent) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/angryrock/play.rb', line 30

def has_winner?(opponent)
  self.move != opponent.move
end

#winner(opponent) ⇒ Object

fetch will raise exception when the key is not one of the allowed choice



34
35
36
37
38
39
40
# File 'lib/angryrock/play.rb', line 34

def winner(opponent)
  if WINS.fetch(self.move)
    self
  else
    opponent
  end
end