Class: Monolens::Object::Rename

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

Instance Attribute Summary

Attributes included from Lens

#options

Instance Method Summary collapse

Methods included from Lens

#fetch_on, #initialize, #is_array!, #is_enumerable!, #is_hash!, #is_string!, #option

Instance Method Details

#call(arg, *rest) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/monolens/object/rename.rb', line 6

def call(arg, *rest)
  is_hash!(arg)

  dup = arg.dup
  options.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