Class: OpenStruct

Inherits:
Object
  • Object
show all
Defined in:
lib/australium/ref/open_struct_deep_clone.rb

Instance Method Summary collapse

Instance Method Details

#initialize_clone(other) ⇒ Object


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/australium/ref/open_struct_deep_clone.rb', line 3

def initialize_clone(other)
  super
  self.each_pair do |key, value|
    if value.is_a?(OpenStruct)
      self[key] = value.clone
    elsif value.is_a?(Enumerable)
      if value.respond_to?(:each_pair)
        self[key] = value.clone
        self[key] = self[key].each_pair do |k, v|
          self[key][k] = v.clone rescue v
        end
      elsif value.respond_to?(:map)
        self[key] = value.map { |x| x.clone rescue x }
      end
    end
  end
end