From: Trans Date: 2005-01-27T23:30:55+09:00 Subject: Re: Duping a class causes error Robert Klemme wrote: > "Trans" schrieb im Newsbeitrag > news:1106832987.976217.139210@f14g2000cwb.googlegroups.com... > > Maybe someone can offer me a possible reason for this. I have a set of > > classes in a module called Markers. I have a module method, > > Markers#list, that does nothing more than collects them into an array. > > Then in my program when I do: > > > > | markers = Markers.list > > > > It works. But when I do: > > > > | markers = Markers.list.collect { |m| nm = m.dup ; nm } > > You can also do: > > markers = Markers.list.collect { |m| m.dup } Thanks. That true, but the line I ultimately want is: | markers = Markers.list.collect { |m| nm = m.dup ; nm.parser = self; nm } I need to pass the current parser object down to the markers themselves b/c I do "reentrant" pasrsing. But obviously I don't want to effect the Classes themselves with this state info in case they are used by another parser, so I'm duplicating them. > > It does not work. > > > > I don't understand why. Obviously my initial thought is that something > > about my Marker classes must not be shallow, but they're just classes, > > made of methods and have no state, so I don't see how that can be. > > So Markers.list returns a list of class objects? Yes. Here, Markers.list returns [MarkUps::Markers::Command, MarkUps::Markers::Verbatim, MarkUps::Markers::Outline, MarkUps::Markers::Document, MarkUps::Markers::Paragraph, MarkUps::Markers::Table] and the dup'd collection returns: [#, #, #, #, #, #] > > (Actually they do have a small bit of boolean state in a class instance > > var, but I check and it is being duplicated.) > > I just don't get it. Any ideas? > > What exactly goes wrong? Unfortunately it is strange. The Outline Marker which tells the parser how to identify and parse an outline fails. T.