Skip to content

Instantly share code, notes, and snippets.

@koriroys
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koriroys/9494460 to your computer and use it in GitHub Desktop.
Save koriroys/9494460 to your computer and use it in GitHub Desktop.
Grandma is deaf!
def deaf_grandma
conversation = []
puts "Say something to Grandma, dear."
until end?(conversation) do
conversation << gets.chomp
puts response(conversation.last)
end
end
GOODBYE = ->(m) { m == "I love ya, Grandma, but I've got to go." }
SHOUTING = ->(m) { m == m.upcase }
END_CONVERSATION = ->(c) { c.last(3) == ["I love ya, Grandma, but I've got to go.", "", ""] }
SILENT = ->(m) { m == "" }
def end?(conversation)
END_CONVERSATION.call(conversation)
end
def response(input)
case input
when SILENT
when SHOUTING
"NO, NOT SINCE 1983!"
when GOODBYE
"Goodbye, Sonny."
else
"HUH?! SPEAK UP, SONNY!"
end
end
deaf_grandma
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment