Sha256: 12fda493a511da654a4b0747452174ee161b993999479c5be87642da333790fe

Contents?: true

Size: 927 Bytes

Versions: 8

Compression:

Stored size: 927 Bytes

Contents

# frozen_string_literal: true

module Anyway
  module Ext
    # Extend Object through refinements
    module DeepDup
      refine ::Hash do
        # Based on ActiveSupport http://api.rubyonrails.org/classes/Hash.html#method-i-deep_dup
        def deep_dup
          each_with_object(dup) do |(key, value), hash|
            hash[key] = if value.is_a?(::Hash) || value.is_a?(::Array)
                          value.deep_dup
                        else
                          value
                        end
          end
        end
      end

      refine ::Array do
        # From ActiveSupport http://api.rubyonrails.org/classes/Array.html#method-i-deep_dup
        def deep_dup
          map do |value|
            if value.is_a?(::Hash) || value.is_a?(::Array)
              value.deep_dup
            else
              value
            end
          end
        end
      end

      using self
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
anyway_config-1.4.4 lib/anyway/ext/deep_dup.rb
anyway_config-1.4.3 lib/anyway/ext/deep_dup.rb
anyway_config-1.4.2 lib/anyway/ext/deep_dup.rb
anyway_config-1.4.1 lib/anyway/ext/deep_dup.rb
anyway_config-1.4.0 lib/anyway/ext/deep_dup.rb
anyway_config-1.3.1 lib/anyway/ext/deep_dup.rb
anyway_config-1.3.0 lib/anyway/ext/deep_dup.rb
anyway_config-1.2.0 lib/anyway/ext/deep_dup.rb