Skip to content

Instantly share code, notes, and snippets.

@davidbalbert
Last active August 29, 2015 14:21
Show Gist options
  • Save davidbalbert/fb8bab10624519490611 to your computer and use it in GitHub Desktop.
Save davidbalbert/fb8bab10624519490611 to your computer and use it in GitHub Desktop.
not.rb: fun with monkey patching with Zach Allaun
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