Thank you, James. Now I understand the code. But what is difference
between these two methods(follow your previous example codes):
def make_another_object1
self.class.new
end
def make_another_object2
self.clone
end
Are they the same if self.class.new takes no argument?
They are not the same. Have a look:
Initializing a Copy...
Initializing a Copy...
=> #<Copy:0x59204 @arg=nil>
Notice how clone() didn't call initialize() and it did copy the
instance variable. Calling the constructor could change things
though, as I've shown here.
clone() also duplicates some of Ruby's internal state, like whether or
not an object is frozen?(). Calling new() would make a fresh new
object though and thus lose such details.
Hope that helps.
James Edward Gray II