Class: Project::Caveman
- Inherits:
-
Object
- Object
- Project::Caveman
- Defined in:
- lib/caveman.rb
Constant Summary collapse
- SUBSTITUTES =
{ "I" => "me", "am " => "", "don't" => "no" }
Instance Method Summary collapse
Instance Method Details
#call ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/caveman.rb', line 26 def call greet_user loop do take_input break if @input == 'exit' puts sub_string end end |
#greet_user ⇒ Object
18 19 20 |
# File 'lib/caveman.rb', line 18 def greet_user puts "you talk. me repeat. say exit, me quit." end |
#sub_string ⇒ Object
12 13 14 15 16 |
# File 'lib/caveman.rb', line 12 def sub_string new_string = @input SUBSTITUTES.each {|word, replacement| new_string = new_string.gsub(/\b#{word}\b/, replacement)} "grunt...#{new_string.downcase}" end |
#take_input ⇒ Object
22 23 24 |
# File 'lib/caveman.rb', line 22 def take_input @input = gets.strip end |