Class: Monolens::Object::Keys

Inherits:
Object
  • Object
show all
Includes:
Lens
Defined in:
lib/monolens/stdlib/object/keys.rb

Instance Attribute Summary

Attributes included from Lens

#options

Instance Method Summary collapse

Methods included from Lens

#fail!, included, #initialize

Methods included from Lens::FetchSupport

#fetch_on

Instance Method Details

#call(arg, world = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/monolens/stdlib/object/keys.rb', line 10

def call(arg, world = {})
  is_hash!(arg, world)

  lenses = option(:lenses)
  dup = {}
  arg.each_pair do |attr, value|
    deeper(world, attr) do |w|
      lensed = lenses.call(attr, w)
      lensed = lensed.to_sym if lensed && attr.is_a?(Symbol)
      dup[lensed] = value
    end
  end
  dup
end