Module: RmsApiRuby::HashKeysCamelizable

Included in:
RestApi::Base
Defined in:
lib/rms_api_ruby/utility/hash_keys_camelizable.rb

Instance Method Summary collapse

Instance Method Details

#camelize_keys(hash, first_letter = :upper) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/rms_api_ruby/utility/hash_keys_camelizable.rb', line 5

def camelize_keys(hash, first_letter = :upper)
  return nil if hash.nil?
  hash.each_with_object({}) do |(key, val), acc|
    if val.is_a?(Array)
      val = val.map { |v| to_camel_keys(v, first_letter) }
    elsif val.is_a?(Hash)
      val = camelize_keys(val, first_letter)
    end
    acc[camel_key(key, first_letter)] = val
  end
end