Module: HashConverter
- Defined in:
- lib/locomotive/common/core_ext/hash.rb
Overview
Big thanks to Tim Ruffles (github.com/timruffles) gist.github.com/timruffles/2780508
Class Method Summary collapse
-
.convert(obj, *method) ⇒ Object
FIXME: not sure it will be ever needed def to_camel_case hash convert hash, :camelize, :lower end.
- .to_string(hash) ⇒ Object
- .to_sym(hash) ⇒ Object
- .to_underscore(hash) ⇒ Object
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 |