Skip to content

Instantly share code, notes, and snippets.

@elight
Created June 20, 2014 18:04
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 elight/cd1baa30297828b4621f to your computer and use it in GitHub Desktop.
Save elight/cd1baa30297828b4621f to your computer and use it in GitHub Desktop.
class Bob
def hey(what)
what = forget_that_noise(what)
if saying_a_whole_lotta_nothing?(what)
"Fine. Be that way!"
elsif shouting_at_me?(what)
"Woah, chill out!"
elsif asking_me_something?(what)
"Sure."
else
"Whatever."
end
end
private
def shouting_at_me?(what)
words = what.just_gimme_letters_k_plz.split
return false if words.empty?
words.all_caps?
end
def saying_a_whole_lotta_nothing?(what)
what.strip.empty?
end
def asking_me_something?(what)
what =~ /\?$/
end
def forget_that_noise(what)
return what unless what.include?("\n")
what.split("\n").last
end
end
class String
def just_gimme_letters_k_plz
gsub(/[\W\d]+/, " ")
end
end
class Array
def all_caps?
all? { |v| v =~ /[A-Z]+/ }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment