Module: Footing::NilClass

Defined in:
lib/extensions/nil_class.rb

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object

Similar to ActiveSupport’s #try added to NilClass. Calling [] on nil always returns nil. It becomes especially helpful when navigating through deeply nested Hashes.

Examples:

dict = {}
dict[:foo][:bar][:other] # => nil

Parameters:

  • key (Object)

    The key to lookup.



13
14
15
# File 'lib/extensions/nil_class.rb', line 13

def [](key)
  nil
end