Skip to content

Instantly share code, notes, and snippets.

@jmmastey
Created June 9, 2014 18:06
Show Gist options
  • Save jmmastey/e5ccad39d6fac57eba07 to your computer and use it in GitHub Desktop.
Save jmmastey/e5ccad39d6fac57eba07 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