Created
August 11, 2013 09:03
-
-
Save jordelver/6204090 to your computer and use it in GitHub Desktop.
"Black hole" Null Object - Responds to any chained message
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 NullObject < BasicObject | |
def method_missing(*) | |
self | |
end | |
def respond_to_missing?(name) | |
true | |
end | |
end | |
class Foo | |
def bar(collaborator) | |
collaborator.baz.boo.blah.bar.foo | |
end | |
end | |
Foo.new.bar(NullObject.new) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment