I’m having a problem defining inner classes. The outer class is a
child of another class, which makes reusing the name for defining
inner classes a little cumbersome.
For example, if the outer class is:
class OuterClass < AbstractOuterClass
…
end
and in InnerClass.rb I have:
class OuterClass
class InnerClass
…
end
end
I get the following error:
warning: already initialized constant OuterClass
… which I’m assuming comes from the fact that the interpreter
thinks I want to redefine OuterClass as having no parent. If I change
my InnerClass code to
class OuterClass < AbstractOuterClass
class InnerClass
…
end
end
… then it works. Which is fine, except I have maybe 20 inner
classes and I’d rather not duplicate the OuterClass inheritance in
each file.
I’m curious why you have that many “inner” classes. Mind sharing?
If I had 20 of them and they were substantial enough to deserve their own
files, I think I would have put them inside a module instead of inside a
class. At least in the scenarios I can think of.
k
“Francis Hwang” sera@fhwang.net wrote in message
news:a05100303b933cd300ae6@[10.0.1.6]…
···
I’m having a problem defining inner classes. The outer class is a
child of another class, which makes reusing the name for defining
inner classes a little cumbersome.
For example, if the outer class is:
class OuterClass < AbstractOuterClass
…
end
and in InnerClass.rb I have:
class OuterClass
class InnerClass
…
end
end
I get the following error:
warning: already initialized constant OuterClass
… which I’m assuming comes from the fact that the interpreter
thinks I want to redefine OuterClass as having no parent. If I change
my InnerClass code to
class OuterClass < AbstractOuterClass
class InnerClass
…
end
end
… then it works. Which is fine, except I have maybe 20 inner
classes and I’d rather not duplicate the OuterClass inheritance in
each file.