[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Can not find superclass

Yu Co

9/20/2006 12:54:00 AM

Hi all,

I've the following:
I defined two classes 'Super' und 'Sub' in two separate files that look
like this:

class Super < ActiveRecord::Base
end

class Sub < Super
end

After compiling 'Sub' I get the following error message "uninitialized
constant Super (NameError)"
Ruby doesn't consider 'Super' as a class but rather as a constant. Does
anyone know how I can avoid this?

Thanks in advance.

Regards,
yussibaer

--
Posted via http://www.ruby-....

7 Answers

Paul Lutus

9/20/2006 1:08:00 AM

0

Yu Co wrote:

> Hi all,
>
> I've the following:
> I defined two classes 'Super' und 'Sub' in two separate files that look
> like this:
>
> class Super < ActiveRecord::Base
> end
>
> class Sub < Super
> end
>
> After compiling 'Sub' I get the following error message "uninitialized
> constant Super (NameError)"
> Ruby doesn't consider 'Super' as a class but rather as a constant. Does
> anyone know how I can avoid this?
>
> Thanks in advance.

You haven't shown enough code. Does the Sub class file have this at the top:

require 'super'

--
Paul Lutus
http://www.ara...

Yu Co

9/20/2006 1:16:00 AM

0

Daniel ----- wrote:
> On 9/20/06, Yu Co <djhackebeil@yahoo.de> wrote:
>> class Sub < Super
>> yussibaer
>>
>>
> I think it's telling you you can't call your class Super. Just choose a
> different name for it.

I renamed it but unfortunately it had no effect

--
Posted via http://www.ruby-....

Yu Co

9/20/2006 1:21:00 AM

0

Paul Lutus wrote:
> Yu Co wrote:
>
>> end
>>
>> After compiling 'Sub' I get the following error message "uninitialized
>> constant Super (NameError)"
>> Ruby doesn't consider 'Super' as a class but rather as a constant. Does
>> anyone know how I can avoid this?
>>
>> Thanks in advance.
>
> You haven't shown enough code. Does the Sub class file have this at the
> top:
>
> require 'super'

That's all of the code I have. I have just two empty classes - one
should be the subclass and the other the superclass.

After writing "require 'super'" at the top of the 'sub'file I get
"uninitialized constant ActiveRecord (NameError)"

Odd, isn't ?

--
Posted via http://www.ruby-....

Paul Lutus

9/20/2006 1:32:00 AM

0

Yu Co wrote:

/ ...

>> You haven't shown enough code. Does the Sub class file have this at the
>> top:
>>
>> require 'super'
>
> That's all of the code I have. I have just two empty classes - one
> should be the subclass and the other the superclass.
>
> After writing "require 'super'" at the top of the 'sub'file I get
> "uninitialized constant ActiveRecord (NameError)"
>
> Odd, isn't ?

Not, it's not odd, it means that, because you put "require 'super'" at the
top of the sub class file, the sub class found the super class, and you now
have an new problem. The new problem is the absence of:

require 'activerecord'

at the top of the super class file.

Before, the sub class couldn't find a definition for 'super'. Now super
can't find a definition for 'activerecord'.

Each Ruby source file that requires information from outside itself ... must
say so.

--
Paul Lutus
http://www.ara...

Yu Co

9/20/2006 2:28:00 AM

0

Paul Lutus wrote:
> Yu Co wrote:
>
> / ...
>
>>
>> Odd, isn't ?
>
> Not, it's not odd, it means that, because you put "require 'super'" at
> the
> top of the sub class file, the sub class found the super class, and you
> now
> have an new problem. The new problem is the absence of:
>
> require 'activerecord'
>
> at the top of the super class file.
>
> Before, the sub class couldn't find a definition for 'super'. Now super
> can't find a definition for 'activerecord'.
>
> Each Ruby source file that requires information from outside itself ...
> must
> say so.

Many thanks for the response Paul,
after putting "require 'activerecord'" at the top of the super class I
have now a new error message
"{RUBY_HOME}/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
`gem_original_require': no such file to load -- activeRecord
(LoadError)"
Do you know how to handle that?


--
Posted via http://www.ruby-....

Logan Capaldo

9/20/2006 2:38:00 AM

0

On Wed, Sep 20, 2006 at 11:27:47AM +0900, Yu Co wrote:
> Paul Lutus wrote:
> > Yu Co wrote:
> >
> > / ...
> >
> >>
> >> Odd, isn't ?
> >
> > Not, it's not odd, it means that, because you put "require 'super'" at
> > the
> > top of the sub class file, the sub class found the super class, and you
> > now
> > have an new problem. The new problem is the absence of:
> >
> > require 'activerecord'
> >
> > at the top of the super class file.
> >
> > Before, the sub class couldn't find a definition for 'super'. Now super
> > can't find a definition for 'activerecord'.
> >
> > Each Ruby source file that requires information from outside itself ...
> > must
> > say so.
>
> Many thanks for the response Paul,
> after putting "require 'activerecord'" at the top of the super class I
> have now a new error message
> "{RUBY_HOME}/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
> `gem_original_require': no such file to load -- activeRecord
> (LoadError)"
> Do you know how to handle that?
>
It's require 'active_record' (Note the underscore).
>
> --
> Posted via http://www.ruby-....

Yu Co

9/20/2006 2:44:00 AM

0

Logan Capaldo wrote:
> On Wed, Sep 20, 2006 at 11:27:47AM +0900, Yu Co wrote:
>> > top of the sub class file, the sub class found the super class, and you
>> > Each Ruby source file that requires information from outside itself ...
>>
> It's require 'active_record' (Note the underscore).

thnx logan. That's the point. And sorry for the stupid mistake of mine.

--
Posted via http://www.ruby-....