Misc #9128 ยป 0001-added-clarification-of-differences-between-Object-cl.patch
object.c | ||
---|---|---|
* obj.clone -> an_object
|
||
*
|
||
* Produces a shallow copy of <i>obj</i>---the instance variables of
|
||
* <i>obj</i> are copied, but not the objects they reference. Copies
|
||
* <i>obj</i> are copied, but not the objects they reference. This
|
||
* includes any modules that the object has been extended with. Copies
|
||
* the frozen and tainted state of <i>obj</i>. See also the discussion
|
||
* under <code>Object#dup</code>.
|
||
*
|
||
* class Klass
|
||
* attr_accessor :str
|
||
* end
|
||
*
|
||
* module Foo
|
||
* def foo; 'foo'; end
|
||
* end
|
||
*
|
||
* s1 = Klass.new #=> #<Klass:0x401b3a38>
|
||
* s1.str = "Hello" #=> "Hello"
|
||
* s1.extend(Foo) #=> #<Klass:0x401b3a38>
|
||
* s2 = s1.clone #=> #<Klass:0x401b3998 @str="Hello">
|
||
* s2.str[1,4] = "i" #=> "i"
|
||
* s1.inspect #=> "#<Klass:0x401b3a38 @str=\"Hi\">"
|
||
* s2.inspect #=> "#<Klass:0x401b3998 @str=\"Hi\">"
|
||
* s2.foo #=> "foo"
|
||
*
|
||
* s3 = s1.dup #=> #<Klass:0x401b3798 @str="Hello">
|
||
* s3.foo #=> NoMethodError: undefined method `foo' for #<Klass:0x401b3798>
|
||
*
|
||
* This method may have class-specific behavior. If so, that
|
||
* behavior will be documented under the #+initialize_copy+ method of
|