Class: Kaibaibo::Player
- Inherits:
-
Object
- Object
- Kaibaibo::Player
- Defined in:
- lib/kaibaibo/player.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
Instance Method Summary collapse
- #gather_choice ⇒ Object
-
#initialize(name = "mister_no_name") ⇒ Player
constructor
A new instance of Player.
- #throw(choice) ⇒ Object
Constructor Details
#initialize(name = "mister_no_name") ⇒ Player
Returns a new instance of Player.
4 5 6 7 |
# File 'lib/kaibaibo/player.rb', line 4 def initialize(name = "mister_no_name") @name = name @status = nil end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/kaibaibo/player.rb', line 3 def name @name end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
3 4 5 |
# File 'lib/kaibaibo/player.rb', line 3 def status @status end |
Class Method Details
.get_name ⇒ Object
13 14 15 16 |
# File 'lib/kaibaibo/player.rb', line 13 def self.get_name puts "What's your name?" gets.chomp end |
Instance Method Details
#gather_choice ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/kaibaibo/player.rb', line 18 def gather_choice puts "#{@name}, enter your choice" choice = gets.strip case choice when "rock" throw(:rock) when "paper" throw(:paper) when "scissors" throw(:scissors) else puts "Incorrect input" gather_choice end end |
#throw(choice) ⇒ Object
9 10 11 |
# File 'lib/kaibaibo/player.rb', line 9 def throw(choice) @status = choice end |