Why do I receive this error?

So I’ve returned today with a new problem… I get this error, and I
know it’s probably something very easy to fix, but I can’t seem to
figure it out…

Here is my code:
http://pastebin.com/ZS3Qrvtt

And here is the error I get:

C:\Users\Paetilium\Desktop\RoboSteve\RoboEngine.rb:5:in initialize': uninitialized constant RoboEngine::Init (NameError) from C:\Users\PandE\Desktop\RoboSteve\RoboEngine.rb:51:innew’
from C:\Users\PandE\Desktop\RoboSteve\RoboEngine.rb:51
Initializing…

On Sun, Jan 22, 2012 at 11:42, Paet Worlds II [email protected]
wrote:

And here is the error I get:

C:\Users\Paetilium\Desktop\RoboSteve\RoboEngine.rb:5:in `initialize’:
uninitialized constant RoboEngine::Init (NameError)

What the error message is saying is that within the context of
RoboEngine::initialize, it has no clue what Init is, and the first
letter is uppercase so it’s taking it as a constant. There are (at
least) two ways you can fix this.

The horrible ugly klugy way that should make everyone want to rinse
their eyeballs in bleach for having read it, is to make Init a global
variable. This is So Wrong that I’m not going to tell you how, though
you could easily Google it.

The cleaner way would be to make Init, within RoboEngine#initialize, a
parameter. (Of course, you’d then lowercase the name, at least the
first letter, so it’s no longer a constant.) That has many
advantages. Mainly, you will certainly know what it is, because it’s
been passed in. Also, the caller won’t have to have set up something
specifically called Init, it can call it whatever it wants, and even
have several of them to choose from at call time.

Note that you’ll have the same problem with ThoughtP in
Initialization#action1.

Any time you have Ruby complaining about not knowing what something
is, like method missing, uninitialized constant, etc., ask yourself:
how is it supposed to know, and is that good clean engineering or a
horrible quick and dirty kluge, in which case what would be better?

-Dave

Dave A. wrote in post #1042042:

On Sun, Jan 22, 2012 at 11:42, Paet Worlds II [email protected]
wrote:

And here is the error I get:

C:\Users\Paetilium\Desktop\RoboSteve\RoboEngine.rb:5:in `initialize’:
uninitialized constant RoboEngine::Init (NameError)

What the error message is saying is that within the context of
RoboEngine::initialize, it has no clue what Init is, and the first
letter is uppercase so it’s taking it as a constant. There are (at
least) two ways you can fix this.

The horrible ugly klugy way that should make everyone want to rinse
their eyeballs in bleach for having read it, is to make Init a global
variable. This is So Wrong that I’m not going to tell you how, though
you could easily Google it.

The cleaner way would be to make Init, within RoboEngine#initialize, a
parameter. (Of course, you’d then lowercase the name, at least the
first letter, so it’s no longer a constant.) That has many
advantages. Mainly, you will certainly know what it is, because it’s
been passed in. Also, the caller won’t have to have set up something
specifically called Init, it can call it whatever it wants, and even
have several of them to choose from at call time.

Note that you’ll have the same problem with ThoughtP in
Initialization#action1.

Any time you have Ruby complaining about not knowing what something
is, like method missing, uninitialized constant, etc., ask yourself:
how is it supposed to know, and is that good clean engineering or a
horrible quick and dirty kluge, in which case what would be better?

-Dave

Well… I tried that and received:

C:\Users\Paetilium\Desktop\RoboSteve\RoboEngine.rb:5:in initialize': undefined local variable or methodinit’ for #RoboEngine:0x2f7f2faa
(NameError)
from C:\Users\PandE\Desktop\RoboSteve\RoboEngine.rb:58:in `new’
from C:\Users\PandE\Desktop\RoboSteve\RoboEngine.rb:58

I mean… I don’t even know what "#<0x2f7f2faa> means…

Your action1 in Initialization and testforaccess in ThoughtProcess might
as
well be class methods instead of instance methods going by your current
code. If you do that, you can then say Initialization.action1 inside
your
initialize method in RoboEngine.

suteerth wrote in post #1042053:

Your action1 in Initialization and testforaccess in ThoughtProcess might
as
well be class methods instead of instance methods going by your current
code. If you do that, you can then say Initialization.action1 inside
your
initialize method in RoboEngine.

Thank’s a ton :slight_smile: I didn’t even realize I hadn’t made them that way…
=.=

On Sun, Jan 22, 2012 at 12:24, Paet Worlds II [email protected]
wrote:

Well… I tried that

How? Please show the changed code. Looks to me like you probably
just changed the name, rather than actually make it a parameter. Do
you know how to do that?

C:\Users\PandE\Desktop\RoboSteve\RoboEngine.rb:5:in initialize': undefined local variable or methodinit’ for #RoboEngine:0x2f7f2faa
(NameError)
from C:\Users\PandE\Desktop\RoboSteve\RoboEngine.rb:58:in `new’
from C:\Users\PandE\Desktop\RoboSteve\RoboEngine.rb:58

I mean… I don’t even know what "#<0x2f7f2faa> means…

Don’t worry about that, it’s just the memory address of that
particular RoboEngine object. (That can help distinguish one from
another object of the same class.) What it’s saying is that, within
the context of running RoboEngine#new, it doesn’t know what “init”
refers to. Same as you got before, just now starting with a lowercase
i.

-Dave

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs