module Surrealist::HashUtils
A helper class for hashes transformations.
Constants
- EMPTY_HASH
Public Class Methods
camelize_hash(hash)
click to toggle source
Converts hash's keys to camelBack keys.
@param [Hash] hash a hash to be camelized.
@return [Hash] camelized hash.
# 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
Private Class Methods
camelize_key(key, first_upper = true)
click to toggle source
Converts symbol to string and camelizes it.
@param [String | Symbol] key a key to be camelized. @param [Boolean] first_upper should the first letter be capitalized.
@return [String | Symbol] camelized key of a hash.
# File lib/surrealist/hash_utils.rb, line 30 def camelize_key(key, first_upper = true) if key.is_a? Symbol Surrealist::StringUtils.camelize(key.to_s, first_upper).to_sym elsif key.is_a? String Surrealist::StringUtils.camelize(key, first_upper) else key end end