Skip to content

Instantly share code, notes, and snippets.

@jmmastey
Created June 6, 2014 14:47
Show Gist options
  • Save jmmastey/8977391478bd2911efd7 to your computer and use it in GitHub Desktop.
Save jmmastey/8977391478bd2911efd7 to your computer and use it in GitHub Desktop.
class Bob
# man, that multi-line made these uglier and more brittle. sad.
MATCHERS = {
/^ *\Z/ => "Fine. Be that way!", # silence
/^[^a-z]+!$/ => "Woah, chill out!", # shouting, no lowercase
/^[A-Z ]+\??$/ => "Woah, chill out!", # speaking loudly, still rude.
/\?\Z/ => "Sure.", # questions
/.*/ => "Whatever." # fallthrough, everything else
}
def hey(msg)
MATCHERS.each do |match,message|
return message if msg =~ match
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment