Skip to content

Instantly share code, notes, and snippets.

@jordelver
Created August 11, 2013 09:03
Show Gist options
  • Save jordelver/6204090 to your computer and use it in GitHub Desktop.
Save jordelver/6204090 to your computer and use it in GitHub Desktop.
"Black hole" Null Object - Responds to any chained message
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