From: Damjan Rems Date: 2012-09-19T15:00:30+09:00 Subject: Re: Bug or feature Robert Klemme wrote in post #1076534: > On Tue, Sep 18, 2012 at 8:44 PM, Damjan Rems > 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 So there is a good reason not to implement object duplication (deep cloning). Results may be unpredictable so better don't do it. Although I never liked the argument if it is good for them than it is good for us. by TheR -- Posted via http://www.ruby-forum.com/.