Module: SC::Cloneable

Included in:
Buildfile, Buildfile::Task
Defined in:
lib/sproutcore/buildfile/cloneable.rb

Overview

Mixing for creating easily cloned objects. Borrowed from Rake 0.8.3

Instance Method Summary collapse

Instance Method Details

#cloneObject



26
27
28
29
30
# File 'lib/sproutcore/buildfile/cloneable.rb', line 26

def clone
  sibling = dup
  sibling.freeze if frozen?
  sibling
end

#dupObject

Clone an object by making a new object and setting all the instance variables to the same values.



15
16
17
18
19
20
21
22
23
24
# File 'lib/sproutcore/buildfile/cloneable.rb', line 15

def dup
  sibling = self.class.new
  instance_variables.each do |ivar|
    value = self.instance_variable_get(ivar)
    new_value = value.clone rescue value
    sibling.instance_variable_set(ivar, new_value)
  end
  sibling.taint if tainted?
  sibling
end