Module: Dry::Struct::Hashify

Defined in:
lib/dry/struct/hashify.rb

Overview

Helper for #to_hash implementation

Class Method Summary collapse

Class Method Details

.[](value) ⇒ Hash, Array

Converts value to hash recursively

Parameters:

Returns:

  • (Hash, Array)


8
9
10
11
12
13
14
15
16
# File 'lib/dry/struct/hashify.rb', line 8

def self.[](value)
  if value.respond_to?(:to_hash)
    value.to_hash
  elsif value.respond_to?(:map)
    value.map { |item| self[item] }
  else
    value
  end
end