From: Robert Klemme Date: 2004-05-18T16:58:50+09:00 Subject: Re: Why do #dup and #clone behave differently with respect to instance methods "Florian Gross" schrieb im Newsbeitrag news:2gsdj3F5va1pU1@uni-berlin.de... > Robert Klemme wrote: > > > "While clone is used to duplicate an object, including its internal state, > > dup typically uses the class of the descendent object to create the new > > instance." > > http://www.ruby-doc.org/docs/rdoc/1.9/classes/Object.html#M000889 > > I'm interested in the reasoning behind this. > > I think the rationale is singleton methods being part of internal state. > I'm actually depending on this behavior for stripping singleton methods > from potentially dangerous objects so if this is to be changed I would > need an alternative way to clone objects without their singleton methods. Sounds reasonable. Still *something* strikes me as odd: #class still returns the original class. Why doesn't it return the singleton class? >> class Foo;end => nil >> f=Foo.new => # >> f.class => Foo >> f.class.id => 135026484 >> def f.bar; "bar";end => nil >> f.bar => "bar" >> f.class => Foo >> f.class.id => 135026484 ^^^^^^^^^ One *could* expect something different here. Any comments? Regards robert