Last active
August 29, 2015 13:57
-
-
Save koriroys/9494460 to your computer and use it in GitHub Desktop.
Grandma is deaf!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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