lib/anyway/ext/deep_dup.rb in anyway_config-0.5.1 vs lib/anyway/ext/deep_dup.rb in anyway_config-1.0.0.rc1

- old
+ new

@@ -1,21 +1,33 @@ +# 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] = value.respond_to?(:deep_dup) ? value.deep_dup : value + 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 { |el| el.respond_to?(:deep_dup) ? el.deep_dup : el } + map do |value| + if value.is_a?(::Hash) || value.is_a?(::Array) + value.deep_dup + else + value + end + end end end end end end