module Remap::Extensions::Enumerable
Public Instance Methods
get(*path, trace: [], &fallback)
click to toggle source
Fetches value at {path}
@example Fetch value at path
[[:a, :b], [:c, :d]].get(0, 1) # => :b
@return [Any]
@raise When path cannot be found
# File lib/remap/extensions/enumerable.rb, line 31 def get(*path, trace: [], &fallback) return self if path.empty? key = path.first unless fallback return get(*path, trace: trace) do throw :ignore, trace + [key] end end fetch(key, &fallback).get(*path[1..], trace: trace + [key], &fallback) end
hide(value)
click to toggle source
Creates a hash using {self} as the {path} and {value} as the hash value
@param value [Any] Hash
value
@example A hash from path
[:a, :b].hide('value') # => { a: { b: 'value' } }
@return [Hash]
# File lib/remap/extensions/enumerable.rb, line 17 def hide(value) reverse.reduce(value) do |element, key| { key => element } end end