Sha256: 1135fc3355e02098e17769d433a4248557889219281f5666ac1a90732395d441

Contents?: true

Size: 865 Bytes

Versions: 1

Compression:

Stored size: 865 Bytes

Contents

# frozen_string_literal: true

module WSDirector
  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
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wsdirector-cli-0.4.0 lib/wsdirector/ext/deep_dup.rb