Module: BorrowDirect::Util

Included in:
FindItem::Response
Defined in:
lib/borrow_direct/util.rb

Class Method Summary collapse

Class Method Details

.hash_key_path(hash, *path) ⇒ Object

A utility method that lets you access a nested hash, returning nil if any intermediate hashes are unavailable.



5
6
7
8
9
10
11
12
13
14
# File 'lib/borrow_direct/util.rb', line 5

def hash_key_path(hash, *path)
  result = nil

  path.each do |key|
    return nil unless hash.respond_to? :"[]"
    result = hash = hash[key]
  end

  return result
end