class ElasticAPM::Util::DeepDup
@api private
Makes a deep copy of an Array or Hash NB: Not guaranteed to work well with complex objects, only simple Hash, Array, String, Number, etc.
Public Class Methods
dup(obj)
click to toggle source
# File lib/elastic_apm/util/deep_dup.rb, line 36 def self.dup(obj) new(obj).dup end
new(obj)
click to toggle source
# File lib/elastic_apm/util/deep_dup.rb, line 28 def initialize(obj) @obj = obj end
Public Instance Methods
dup()
click to toggle source
# File lib/elastic_apm/util/deep_dup.rb, line 32 def dup deep_dup(@obj) end
Private Instance Methods
array(arr)
click to toggle source
# File lib/elastic_apm/util/deep_dup.rb, line 50 def array(arr) arr.map { |obj| deep_dup(obj) } end
deep_dup(obj)
click to toggle source
# File lib/elastic_apm/util/deep_dup.rb, line 42 def deep_dup(obj) case obj when Hash then hash(obj) when Array then array(obj) else obj.dup end end
hash(hsh)
click to toggle source
# File lib/elastic_apm/util/deep_dup.rb, line 54 def hash(hsh) result = hsh.dup hsh.each_pair do |key, value| result[key] = deep_dup(value) end result end