Last active
August 29, 2015 14:17
-
-
Save bchase/ffb9ae3a7f5658a44627 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
module Nottable | |
class Notter < BasicObject | |
attr_reader :orig | |
def initialize(orig) | |
@orig = orig | |
end | |
def equal?(other) | |
! orig.equal? other | |
end | |
def _boolean_methods | |
orig.methods.select {|m| m =~ /\?$/} | |
end | |
def method_missing(method, *args, &block) | |
return super unless _boolean_methods.include? method | |
! orig.send method, *args, &block | |
end | |
end | |
def not | |
Notter.new self | |
end | |
end | |
String.include Nottable | |
''.nil? | |
# => false | |
''.not.nil? | |
# => true | |
''.respond_to? :nil? | |
# => true | |
''.not.respond_to? :nil? | |
# => false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment