class Hash

Extend hash with helpers specificic to this gem.

Public Instance Methods

mm_camelize_keys() click to toggle source

Convert the keys of hashes and arrays of hashes using mm_camelize

# File lib/core_ext/hash_extension.rb, line 11
def mm_camelize_keys
  keys_to_mm_camel(self)
end
mm_underscore_keys() click to toggle source

Convert the keys of hashes and arrays of hashes using mm_underscore

# File lib/core_ext/hash_extension.rb, line 6
def mm_underscore_keys
  keys_to_mm_underscore(self)
end
mm_values_to_h() click to toggle source
# File lib/core_ext/hash_extension.rb, line 15
def mm_values_to_h
  mm_values_to_hashes(self)
end

Private Instance Methods

keys_to_mm_camel(value) click to toggle source
# File lib/core_ext/hash_extension.rb, line 33
def keys_to_mm_camel(value)
  case value
  when Array
    value.map { |v| keys_to_mm_camel(v) }
  when Hash
    Hash[value.map { |k, v| [k.mm_camelize, keys_to_mm_camel(v)] }]
  else
    value
  end
end
keys_to_mm_underscore(value) click to toggle source

Convert the keys of hashes and arrays of hashes to mm_underscore

# File lib/core_ext/hash_extension.rb, line 22
def keys_to_mm_underscore(value)
  case value
  when Array
    value.map { |v| keys_to_mm_underscore(v) }
  when Hash
    Hash[value.map { |k, v| [k.mm_underscore, keys_to_mm_underscore(v)] }]
  else
    value
  end
end