Created
May 25, 2011 08:19
-
-
Save AndrewRadev/990562 to your computer and use it in GitHub Desktop.
object.not.predicate?
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
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