Skip to content

Instantly share code, notes, and snippets.

@emasaka
Created December 14, 2012 08:40
Show Gist options
  • Save emasaka/4283689 to your computer and use it in GitHub Desktop.
Save emasaka/4283689 to your computer and use it in GitHub Desktop.
! someobject.foo? -> someobject.not_foo?
# inspired by http://www.msng.info/archives/2012/12/php-not.php
module AutoNot
def method_missing(method, *args)
if /\Anot_(.*\?)\z/ =~ method
! send($1, *args)
end
end
end
foo = ''
foo.extend AutoNot
p foo.not_empty? #=> false
bar = 'aaa'
bar.extend AutoNot
p bar.not_empty? #=> true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment