class Hash
Public Instance Methods
deep_camel_case_lower_keys(hash=self)
click to toggle source
# File lib/ipay/utilities/hash.rb, line 2 def deep_camel_case_lower_keys(hash=self) {}.tap { |h| hash.each { |key, value| h[camel_case_lower_key(key)] = map_value(value, :deep_camel_case_lower_keys) } } end
deep_underscore_keys(hash=self)
click to toggle source
# File lib/ipay/utilities/hash.rb, line 8 def deep_underscore_keys(hash=self) {}.tap { |h| hash.each { |key, value| h[underscore_key(key)] = map_value(value, :deep_underscore_keys) } } end
Private Instance Methods
camel_case_lower_key(key)
click to toggle source
# File lib/ipay/utilities/hash.rb, line 20 def camel_case_lower_key(key) key.to_s.split('_').inject([]){ |buffer, e| buffer.push(buffer.empty? ? e : e.capitalize) }.join.to_sym end
map_value(thing, method)
click to toggle source
# File lib/ipay/utilities/hash.rb, line 24 def map_value(thing, method) case thing when Hash __send__(method, thing) when Array thing.map { |v| map_value(v, method) } else thing end end
underscore_key(key)
click to toggle source
# File lib/ipay/utilities/hash.rb, line 16 def underscore_key(key) key.to_s.underscore.to_sym end