Module: Surrealist::HashUtils

Defined in:
lib/surrealist/hash_utils.rb

Overview

A helper class for hashes transformations.

Constant Summary collapse

EMPTY_HASH =
{}.freeze

Class Method Summary collapse

Class Method Details

.camelize_hash(hash) ⇒ Hash

Converts hash’s keys to camelBack keys.

Parameters:

  • hash (Hash)

    a hash to be camelized.

Returns:

  • (Hash)

    camelized hash.



14
15
16
17
18
19
20
# File 'lib/surrealist/hash_utils.rb', line 14

def camelize_hash(hash)
  return hash unless hash.is_a?(Hash)

  hash.each_with_object({}) do |(k, v), obj|
    obj[camelize_key(k, false)] = camelize_hash(v)
  end
end