Class: AngryRock::Internal::AngryRock
- Inherits:
-
Object
- Object
- AngryRock::Internal::AngryRock
- 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
-
#move ⇒ Object
Returns the value of attribute move.
Instance Method Summary collapse
- #has_winner?(opponent) ⇒ Boolean
-
#initialize(move) ⇒ AngryRock
constructor
A new instance of AngryRock.
-
#winner(opponent) ⇒ Object
fetch will raise exception when the key is not one of the allowed choice.
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
#move ⇒ Object
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
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 |