Module: Dry::Struct::Hashify
- Defined in:
- lib/dry/struct/hashify.rb
Overview
Helper for #to_hash implementation
Class Method Summary collapse
-
.[](value) ⇒ Hash, Array
Converts value to hash recursively.
Class Method Details
.[](value) ⇒ Hash, Array
Converts value to hash recursively
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/dry/struct/hashify.rb', line 10 def self.[](value) if value.is_a?(Struct) value.to_h.transform_values { |current| self[current] } elsif value.respond_to?(:to_hash) value.to_hash.transform_values { |current| self[current] } elsif value.respond_to?(:to_ary) value.to_ary.map { |item| self[item] } else value end end |