Module: HashHelper

Defined in:
lib/cryptoexchange/helpers/hash_helper.rb

Class Method Summary collapse

Class Method Details

.dig(obj, *args) ⇒ Object

“Polyfill” of the Hash#dig method from Ruby 2.3

Examples

  > dig({a: {b: 1}}, :a, :b)
  => 2

  > dig({a: {b: 1}}, :a, :c)
  => nil


12
13
14
15
16
17
18
# File 'lib/cryptoexchange/helpers/hash_helper.rb', line 12

def dig(obj, *args)
  if obj.nil? || args.empty?
    obj
  else
    dig(obj[args.first], *args[1..-1])
  end
end