Skip to content

Instantly share code, notes, and snippets.

@hchood
Last active December 29, 2015 04:58
Show Gist options
  • Save hchood/7618144 to your computer and use it in GitHub Desktop.
Save hchood/7618144 to your computer and use it in GitHub Desktop.
Alpha checkpoint: Echo (Phase 3)
# Alpha: Echo checkpoint (Phase 3)
def playback(input)
if input == "Nothing!"
"Ok, fine!"
elsif input == "I have a lot to say"
puts "Ok, let's hear it!"
multiline_output_from(gets_lines_of_input)
else
"You said: #{input}"
end
end
def gets_lines_of_input
lines_of_input = []
input = nil
until input == "done"
input = gets.chomp
lines_of_input << input unless input == "done"
end
lines_of_input
end
def multiline_output_from(lines_of_input)
num_lines = lines_of_input.length
first = "You said: #{lines_of_input.shift}\n"
last = "Finally you said: #{lines_of_input.pop}\n"
middle = lines_of_input.map{|line| "Then, you said: #{line}\n"}.join
first + middle + last + "Phew! Glad you got all #{num_lines} of those things off your chest!"
end
puts "What do you want to say?"
input = gets.chomp
puts playback(input)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment