Module: ResultClassComponents::KeyTransformation
- Defined in:
- lib/kweerie/result_class_components/key_transformation.rb
Instance Method Summary collapse
Instance Method Details
#deep_stringify_keys(obj) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/kweerie/result_class_components/key_transformation.rb', line 5 def deep_stringify_keys(obj) case obj when Hash obj.transform_keys(&:to_s) .transform_values { |v| deep_stringify_keys(v) } when Array obj.map { |item| item.is_a?(Hash) ? deep_stringify_keys(item) : item } else obj end end |
#deep_symbolize_keys(obj) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/kweerie/result_class_components/key_transformation.rb', line 17 def deep_symbolize_keys(obj) case obj when Hash obj.transform_keys(&:to_sym) .transform_values { |v| deep_symbolize_keys(v) } when Array obj.map { |item| item.is_a?(Hash) ? deep_symbolize_keys(item) : item } else obj end end |