Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/values_at_nested/core_ext/hash/values_at_nested.rb
Instance Method Summary collapse
-
#values_at_nested(*nested_keys) ⇒ Object
Returns an array that holds the values of the given keys list of various depth.
Instance Method Details
#values_at_nested(*nested_keys) ⇒ Object
Returns an array that holds the values of the given keys list of various depth.
Example:
hash = { a: 58, b: { x: true, y: false }, c: nil }
hash.values_at_nested(:b, :c) # => [58, nil]
hash.values_at_nested(:a, b: [:x]) # => [58, [true]]
hash.values_at_nested(:a, b: [:x, :y]) # => [58, [true, false]]
13 14 15 |
# File 'lib/values_at_nested/core_ext/hash/values_at_nested.rb', line 13 def values_at_nested(*nested_keys) nested_keys.empty? ? [] : iterate_over_nested(nested_keys) { |k| self.dig(*k) } end |