No commit activity in last 3 years
No release in over 3 years
Chain methods on nil without getting exceptions.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

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.