Created
August 7, 2008 23:46
-
-
Save brennandunn/4518 to your computer and use it in GitHub Desktop.
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
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