Last active
August 29, 2015 14:21
-
-
Save davidbalbert/fb8bab10624519490611 to your computer and use it in GitHub Desktop.
not.rb: fun with monkey patching with Zach Allaun
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 | |
def not | |
NotProxy.new(self) | |
end | |
end | |
class NotProxy | |
def initialize(obj) | |
@obj = obj | |
end | |
def method_missing(name, *args, &block) | |
!@obj.public_send(name, *args, &block) | |
end | |
def respond_to_missing?(*args) | |
@obj.respond_to?(*args) || super | |
end | |
end | |
[1,2,3].not.empty? #=> true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment