On Tue, Sep 18, 2012 at 8:44 PM, Damjan Rems <[email protected]> wrote:
> Robert Klemme wrote in post #1076432:
>
>> For full object tree copy you can do
>>
>> irb(main):007:0> c = Marshal.load(Marshal.dump(a))
>
> Why is real cloning not implemented in ruby, since this fake cloning can
> lead to a lot of troubles.
What do you mean - "real cloning"? Shallow copy is as real as deep
copy. They are just different concepts. If you think about it for a
moment a deep copy is significantly more difficult to realize
(especially with object graphs which have different paths to the same
instance). It is totally reasonable to provide a shallow copy as
default - btw. Java does it, too.
And you can simply create your deep copy method:
class Object
def clone_deep
Marshal.load(Marshal.dump(self))
end
end
Kind regards
robert
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
-- You received this message because you are subscribed to the Google Groups
ruby-talk-google group. To post to this group, send email to
[email protected]. To unsubscribe from this group, send email
to [email protected]. For more options, visit this
group at https://groups.google.com/d/forum/ruby-talk-google?hl=en