NullObject
Dead simple library to create null objects (objects that respond to all messages)
Usage
Respond to ALL the things:
obj = NullObject.new
obj.foo # => nil
obj. # => nil
Respond to SOME of the things:
obj = NullObject.new(:foo, :bar)
obj.foo # => nil
obj. # => nil
obj.baz # raises NoMethodError
Respond to SOME of the things with CERTAIN return values:
obj = NullObject.new(:foo => :bar)
obj.foo # => :bar
obj.baz # raises NoMethodError
Respond to ALL of the things with a CERTAIN return value:
obj = NullObject.new { "foo" }
obj.foo # => "foo"
obj. # => "foo"
Respond to ALL of the things with self
:
obj = NullObject.new { obj }
obj.foo # => obj
obj.foo..baz # => obj
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request