Class: Rpsshoot::Player
- Inherits:
-
Object
- Object
- Rpsshoot::Player
- Defined in:
- lib/rpsshoot/player.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#symbol ⇒ Object
readonly
Returns the value of attribute symbol.
Instance Method Summary collapse
-
#initialize(symbol, name) ⇒ Player
constructor
A new instance of Player.
-
#shoot ⇒ Object
Each player takes a turn.
Constructor Details
#initialize(symbol, name) ⇒ Player
Returns a new instance of Player.
8 9 10 11 |
# File 'lib/rpsshoot/player.rb', line 8 def initialize(symbol, name) @symbol = symbol @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/rpsshoot/player.rb', line 6 def name @name end |
#symbol ⇒ Object (readonly)
Returns the value of attribute symbol.
6 7 8 |
# File 'lib/rpsshoot/player.rb', line 6 def symbol @symbol end |
Instance Method Details
#shoot ⇒ Object
Each player takes a turn
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rpsshoot/player.rb', line 14 def shoot = ["rock", "paper", "scissors"] puts "#{@name} please enter rock, paper or scissors: (or 'quit' to exit)" selection = STDIN.noecho(&:gets).chomp if .include?(selection) selection elsif selection.downcase == "quit" exit else puts "I'm sorry, that wasn't a valid selection." shoot end end |