module Dry::Struct::Hashify

Helper for {Struct#to_hash} implementation

Public Class Methods

[](value) click to toggle source

Converts value to hash recursively @param [#to_hash, map, Object] value @return [Hash, Array]

# 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