Module: NilSafe

Defined in:
lib/nil_safe.rb,
lib/nil_safe/version.rb

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.get(object:, return_value: nil, arguments:) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/nil_safe.rb', line 4

def self.get(object:, return_value: nil, arguments:)
  return object if arguments.length == 0
  first, *remainder = arguments
  object = object.first if object.class == Array
  keyed_into_hash = object[first.to_s] || object[first.to_sym]
  keyed_into_hash ? self.get(object: keyed_into_hash, return_value: return_value, arguments: remainder) : return_value
end