Module: HashConverter

Defined in:
lib/locomotive/common/core_ext/hash.rb

Overview

Class Method Summary collapse

Class Method Details

.convert(obj, *method) ⇒ Object

FIXME: not sure it will be ever needed def to_camel_case hash

convert hash, :camelize, :lower

end



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/locomotive/common/core_ext/hash.rb', line 24

def convert(obj, *method)
  case obj
  when Hash
    obj.each_with_object({}) do |(k, v), h|
      v = convert(v, *method)
      h[k.send(*method)] = v
    end
  when Array
    obj.map { |m| convert(m, *method) }
  else
    obj
  end
end

.to_string(hash) ⇒ Object



11
12
13
# File 'lib/locomotive/common/core_ext/hash.rb', line 11

def to_string(hash)
  convert(hash, :to_s)
end

.to_sym(hash) ⇒ Object



15
16
17
# File 'lib/locomotive/common/core_ext/hash.rb', line 15

def to_sym(hash)
  convert(hash, :to_sym)
end

.to_underscore(hash) ⇒ Object



7
8
9
# File 'lib/locomotive/common/core_ext/hash.rb', line 7

def to_underscore(hash)
  convert(hash, :underscore)
end