Method: HashTools#deep_map_value

Defined in:
lib/hash_tools.rb

#deep_map_value(enum_of_hashes, path, separator: FWD_SLASH) ⇒ Array

Fetches a deeply nested key from each of the Hashes in a given Array.

arr = [
  {'age' => 12, 'name' => 'Jack'},
  {'age' => 25, 'name' => 'Joe'},
]
deep_map_value(arr, 'age') => [12, 25]

Parameters:

  • enum_of_hashes (Enumerable)

    a list of Hash objects to fetch the values from

  • path (String)

    the paths to the value. Paths may contain numbers for deeply nested arrays ('foo/0/bar')

  • separator (String) (defaults to: FWD_SLASH)

    the path separator, defaults to '/'

Returns:

  • (Array)

    the fetched values



64
65
66
# File 'lib/hash_tools.rb', line 64

def deep_map_value(enum_of_hashes, path, separator: FWD_SLASH)
  enum_of_hashes.map{|h| deep_fetch(h, path, separator: separator)}
end