Class: Monolens::Object::Rename
- Inherits:
-
Object
- Object
- Monolens::Object::Rename
show all
- Includes:
- Lens
- Defined in:
- lib/monolens/stdlib/object/rename.rb
Instance Attribute Summary
Attributes included from Lens
#options
Instance Method Summary
collapse
Methods included from Lens
#fail!, included, #initialize
#fetch_on
Instance Method Details
#call(arg, world = {}) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/monolens/stdlib/object/rename.rb', line 10
def call(arg, world = {})
is_hash!(arg, world)
dup = arg.dup
option(:defn, {}).each_pair do |oldname, newname|
actual_name, value = fetch_on(oldname, arg)
newname = actual_name.is_a?(Symbol) ? newname.to_sym : newname.to_s
dup.delete(actual_name)
dup[newname] = value
end
dup
end
|