Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Allows you to chain methods even if somewhere in the process you start getting nil.
Ruby
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
Gemfile
Gemfile.lock
README.rdoc
nullobject_chain.gemspec

README.rdoc

NullObject Chain

Allows you to chain methods even if somewhere in the process you start getting nil. This gem uses the nullobject gem so if you get nil, you will get Null::Object.instance instead of nil at the end (which converts nicely to string etc).

Example use (I use a hash as an example since it will return nil if there is no value for a key):

NullChainer.use_nullobject = true # if false, then it will use nil instead of Null::Object.instance
my_hash = Hash.new
NullChain(my_hash)["value"]["value"]["value"].get # => Null::Object.instance

Just remember to call #get after chaining your methods and you're good to go!

Version 1.0.0

Breaking change: Null::Object.instance not used by default anymore.

Something went wrong with that request. Please try again.