Skip to content

Instantly share code, notes, and snippets.

@AndrewRadev
Created May 25, 2011 08:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndrewRadev/990562 to your computer and use it in GitHub Desktop.
Save AndrewRadev/990562 to your computer and use it in GitHub Desktop.
object.not.predicate?
if not defined? BasicObject
class BasicObject
m = %w"__id__ __send__ instance_eval == equal?"
(instance_methods - m).each{|m| undef_method(m)}
end
end
class NotDelegator < BasicObject
def initialize(obj)
@_object = obj
end
def method_missing(m, *args, &block)
!@_object.send(m, *args, &block)
end
end
class Object
def not
NotDelegator.new(self)
end
end
# Example:
class Post
attr_accessor :published
def published?
!!@published
end
end
p = Post.new
puts p.published?
puts p.not.published?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment