Class: Wallaby::Utils::HashCloner

Inherits:
Object
  • Object
show all
Defined in:
lib/utils/wallaby/utils.rb

Overview

Service object to clone Hash

Class Method Summary collapse

Class Method Details

.execute(object) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/utils/wallaby/utils.rb', line 35

def self.execute(object)
  # NOTE: `default`/`default_proc` should be cloned as well
  default_method = object.default_proc ? :default_proc : :default
  object
    .each_with_object(object.class.new) { |(key, value), hash| hash[key] = Utils.clone(value) }
    .tap { |hash| hash.try("#{default_method}=", object.try(default_method)) }
end