[Rails] Rails namespace help requested
Michael Engelhart
moosebrookfarm at gmail.com
Wed Dec 14 16:01:44 GMT 2005
HI Zach -
THanks very much for your help. I'm not sure I understand why my
clash exists though because I have this exact scenario:
class StateProvince < ActiveRecord::Base
end
# this is in a directory of lib/ws
module WebServiceModule
class StateProvince
end
end
Isn't the namespace declared for the class inside the module as
::WebServiceModule::StateProvince and the Rails model as
::StateProvince? Aren't those different objects in the eyes or Ruby?
Also I'm not doing inheritance in my WebServiceModule, I'm just
declaring a namespace right?
I'm a bit new to Ruby so it's possible I'm mixing this up but this is
what I understood from reading the pickaxe book.
Thanks again for your help.
MIke
On 12/14/05, zdennis <zdennis at mktec.com> wrote:
> zdennis wrote:
> > Michael Engelhart wrote:
>
> >
> > The problem you are having is that the first time you define/open a
> > class it has to define it's superclass.
> >
> > class A ; end
> > class B < A; end
> >
> > You cannot define/open a class and then later try to subclass it, ie:
> >
> > class A; end
> > class B; end
> > class B < A; end # error!!
> >
> > This is the scenario you're hitting with your namespace clash. Your
> > StateProvince class is being initalized, then when it gets around to
> > loading your StateProvince module it seems you're trying to define
> > inheritance, and you can't do that now.
> >
>
> I don't mean to say it's anything you're doing on purpose. I think ruby finds your StateProvince
> class definition first, then it finds the StateProvince model definition, which is where it tries to
> subclass ActiveRecord::Base. At this point Ruby already has a definition for StateProvince, and
> although ruby lets us reopen the class we can't subclass it because Ruby defines the superclass of a
> class when the class is first read in.
>
> Zach
> _______________________________________________
> Rails mailing list
> Rails at lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
More information about the Rails
mailing list