Sha256: afb18db22ab36ac6ced72c192dd914ab336de3fc33dd52004639d177dd636f7e

Contents?: true

Size: 450 Bytes

Versions: 3

Compression:

Stored size: 450 Bytes

Contents

module Dry
  class Struct
    # Helper for {Struct#to_hash} implementation
    module Hashify
      # Converts value to hash recursively
      # @param [#to_hash, #map, Object] value
      # @return [Hash, Array]
      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
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dry-struct-0.4.0 lib/dry/struct/hashify.rb
dry-struct-0.3.1 lib/dry/struct/hashify.rb
dry-struct-0.3.0 lib/dry/struct/hashify.rb