Module: ServiceObjects::Utils::NormalHash Private

Defined in:
lib/service_objects/utils/normal_hash.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Constructor of hash with keys, symbolized at any level

Examples:

NormalHash.from { "foo" => "bar", "bar" => { "baz", "bar" => "baz" } }
# => { foo: "baz", bar: { "baz", bar: "baz" } }

Class Method Summary collapse

Class Method Details

.from(hash) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Recursively symbolizes keys of hash at any level

Parameters:

  • hash (Hash)

Returns:

  • (Hash)

22
23
24
25
26
27
28
# File 'lib/service_objects/utils/normal_hash.rb', line 22

def self.from(hash)
  return {} unless hash.is_a? Hash

  hash.inject({}) do |out, (key, val)|
    out.merge(key.to_sym => (val.is_a?(Hash) ? from(val) : val))
  end
end