From: Robert Klemme Date: 2004-05-28T22:00:35+09:00 Subject: Re: Struct derivation "Philipp Kern" schrieb im Newsbeitrag news:slrncbbbls.adl.trash@o2.net.philkern.de... > On 2004-05-27, Alan Chen wrote: > > I could be wrong, but I think you actually want: > > class X < Struct.new(:foo,:bar) > > def initialize; end > > end > > You're right. However it should be written class X < Struct.new("X", :foo, :bar) I'd rather don't do that if you're just interested in inheriting from this struct. Because Struct.new("X", :foo, :bar) creates a named struct: 12:09:03 [ContentReporter_BRANCH]: irbs >> x = Struct.new("X", :foo, :bar) => Struct::X >> x => Struct::X >> Struct.constants => ["X", "Tms"] > or something like that. Like this you could get around the warnings Ruby issues > when you redefine the class: > (irb):6: warning: already initialized constant X Which code gives you that warning? I guess you did too much testing in IRB and thus redefined the constant. It works perfectly for me: 12:07:42 [ContentReporter_BRANCH]: irbs >> class X < Struct.new(:foo,:bar) >> def initialize; end >> end => nil >> X => X >> X.ancestors => [X, #, Struct, Enumerable, Object, Kernel] > > Or are you trying to create a new class X which can build new classes like > > struct? > > No, thank you Alan. That's what I searched. I misunderstood Struct a bit |: This can happen too easily. Maybe they should've created another method instead of overloading #new. That can be really confusing in this situation. Regards robert