Skip to content

Instantly share code, notes, and snippets.

@quinn
Created August 27, 2008 16:33
Show Gist options
  • Save quinn/7522 to your computer and use it in GitHub Desktop.
Save quinn/7522 to your computer and use it in GitHub Desktop.
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