Debian Codegraph @

rake.d/vendor/drake-0.9.2.0.3.1/lib/rake/cloneable.rb

raw
1 module Rake
2 # ##########################################################################
3 # Mixin for creating easily cloned objects.
4 #
5 module Cloneable
6 # Clone an object by making a new object and setting all the instance
7 # variables to the same values.
8 def dup
9 sibling = self.class.new
10 instance_variables.each do |ivar|
11 value = self.instance_variable_get(ivar)
12 new_value = value.clone rescue value
13 sibling.instance_variable_set(ivar, new_value)
14 end
15 sibling.taint if tainted?
16 sibling
17 end
18
19 def clone
20 sibling = dup
21 sibling.freeze if frozen?
22 sibling
23 end
24 end
25 end