Class: Rockpaperscissors::Player
- Inherits:
-
Object
- Object
- Rockpaperscissors::Player
- Defined in:
- lib/rockpaperscissors/player.rb
Instance Attribute Summary collapse
-
#choice ⇒ Object
Returns the value of attribute choice.
-
#player_id ⇒ Object
readonly
Returns the value of attribute player_id.
Instance Method Summary collapse
-
#initialize(player_id) ⇒ Player
constructor
A new instance of Player.
- #move ⇒ Object
Constructor Details
#initialize(player_id) ⇒ Player
Returns a new instance of Player.
6 7 8 |
# File 'lib/rockpaperscissors/player.rb', line 6 def initialize(player_id) @player_id = player_id end |
Instance Attribute Details
#choice ⇒ Object
Returns the value of attribute choice.
3 4 5 |
# File 'lib/rockpaperscissors/player.rb', line 3 def choice @choice end |
#player_id ⇒ Object (readonly)
Returns the value of attribute player_id.
4 5 6 |
# File 'lib/rockpaperscissors/player.rb', line 4 def player_id @player_id end |
Instance Method Details
#move ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/rockpaperscissors/player.rb', line 10 def move self.choice = nil until valid_input? print "Player #{player_id}, choose rock ('R'), paper ('P') or scissors ('S')\n > " self.choice = gets.chomp.upcase unless valid_input? print "That's not an allowed move!\n" end end self.choice end |