Created
August 27, 2008 16:33
-
-
Save quinn/7522 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 Object | |
# just a more verbose way of reversing predicates. | |
# | |
# lets you do things like | |
# ' '.not_blank? # => false | |
# instead of | |
# !' '.blank? # => false | |
# doesn't work sometimes if someone is using method_missing | |
# somewhere (i.e. rails) | |
def method_missing(method, *args, &block) | |
if matched= method.to_s.match(/(not_)(\w*\?$)/) | |
super unless self.respond_to? matched[2].to_sym | |
!self.send "#{matched[2]}" | |
else | |
super | |
end | |
end | |
# grammar for the masses. | |
# from utility belt, or something. maybe. | |
def is_an? klass | |
is_a? klass | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment