Sha256: 614f86f32e38f2bc053cf382d54b19a195c6496f46e7aa70d7edd1430fed217c

Contents?: true

Size: 645 Bytes

Versions: 3

Compression:

Stored size: 645 Bytes

Contents

# frozen-string-literal: true
module EncryptedFormFields
  module Dfs
    extend self

    def traverse(value, &block)
      if value.respond_to?(:each_pair)
        traverse_hash(value, &block)
      elsif value.is_a?(Array)
        traverse_array(value, &block)
      else
        yield value
      end
    end

    private

    def traverse_hash(hash, &block)
      result = {}.with_indifferent_access
      hash.each_pair do |key, value|
        result[key] = traverse(value, &block)
      end
      result
    end

    def traverse_array(array, &block)
      array.map do |value|
        traverse(value, &block)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
encrypted_form_fields-1.0.0 lib/encrypted_form_fields/dfs.rb
encrypted_form_fields-0.2.4 lib/encrypted_form_fields/dfs.rb
encrypted_form_fields-0.2.3 lib/encrypted_form_fields/dfs.rb