From: Robert Klemme Date: 2005-01-26T19:45:47+09:00 Subject: Re: clone and dup "Keith P. Boruff" schrieb im Newsbeitrag news:89KJd.989$HR6.889@fe10.lga... > After reading about these two methods for the Object class in "Pragmatic > Programmer", I'm still having a hard time understanding the differences. > Can someone point me to some better info on these or explain it (I do > understand the differences between deep and shallow copying). They do both shallow copy. Here's a difference: >> s="foo".freeze => "foo" >> s.frozen? => true >> s.clone.frozen? => true >> s.dup.frozen? => false > Also, in some of the std modules I've peeked at like Find for instance, this > is called for the args: > > def find(*paths) > paths.collect! { |d| d.dup } > ... > end > > Why would one dup the args in place? I definitely don't understand this. Probably because the path names are modified later on and the implementer of find wanted to avoide side effects on the arguments. Or he wanted to make sure that modifications to the argument objects don't affect find() as it is likely to run comparatively long compared to other methods. Kind regards robert