module HashConverter
Big thanks to Tim Ruffles (github.com/timruffles) gist.github.com/timruffles/2780508
Public Class Methods
convert(obj, *method)
click to toggle source
FIXME: not sure it will be ever needed def to_camel_case hash
convert hash, :camelize, :lower
end
# 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)
click to toggle source
# File lib/locomotive/common/core_ext/hash.rb, line 11 def to_string(hash) convert(hash, :to_s) end
to_sym(hash)
click to toggle source
# File lib/locomotive/common/core_ext/hash.rb, line 15 def to_sym(hash) convert(hash, :to_sym) end
to_underscore(hash)
click to toggle source
# File lib/locomotive/common/core_ext/hash.rb, line 7 def to_underscore(hash) convert(hash, :underscore) end