Skip to content

Instantly share code, notes, and snippets.

@brennandunn
Created August 7, 2008 23:46
Show Gist options
  • Save brennandunn/4518 to your computer and use it in GitHub Desktop.
Save brennandunn/4518 to your computer and use it in GitHub Desktop.
class String
def method_missing(method, *args, &block)
if method.to_s =~ /is_(.*?)\?/
self.downcase == $1
else
raise NoMethodError, "Undefined method '#{method}' for #{self.inspect}"
end
end
end
"bob".is_bob? # => true
"jim".is_tom? # => false
"karl".foobar # =>
# ~> -:6:in `method_missing': Undefined method 'foobar' for "karl" (NoMethodError)
# ~> from -:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment