Module: Nero::Util
Instance Method Summary collapse
Instance Method Details
permalink #deep_symbolize_keys(object) ⇒ Object
[View source] [View on GitHub]
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/nero/util.rb', line 5 def deep_symbolize_keys(object) case object when Hash object.each_with_object({}) do |(key, value), result| result[key.to_sym] = deep_symbolize_keys(value) end when Array object.map { |e| deep_symbolize_keys(e) } else object end end |
permalink #deep_transform_values(object, &block) ⇒ Object
[View source] [View on GitHub]
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/nero/util.rb', line 18 def deep_transform_values(object, &block) case object when Hash object.transform_values { |value| deep_transform_values(value, &block) } when Array object.map { |e| deep_transform_values(e, &block) } else yield(object) end end |