I’ve been staring at this for a couple of hours, and I cannot crack the
nut. This SHOULD work, but I’m obviously screwing up. Just cannot see
where. I’m carefully following several examples, but…I cannot get
access to my instance variables.
logging started, at INFO level
setnet-x.rb:5
log = run_log.log
(rdb:1) p run_log.log
NoMethodError Exception: undefined method `log’ for nil:NilClass
(rdb:1)
I would truly appreciate someone’s pointing out the problem here.
Thanks!
Tom
–
Tom C., MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< [email protected] >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)
I haven’t read the rest of your code but I’ll bet the problem is right
there. Ruby is interpreting log and logging_now as local variables. If
you want to call the methods of those names, you have to do:
setnet-x.rb:40
log = run_log.log
(rdb:1) p run_log.log
NoMethodError Exception: undefined method `log’ for nil:NilClass
(rdb:1)
I would truly appreciate someone’s pointing out the problem here.
Thanks!
Tom
Take a look at ManageLog#open. The last expression is a call to puts,
which returns nil. You are setting the variable “run_log” to the result
of the call to open in the debugger, but that result is nil. Then you
try to call “log” on nil, thus the error.
you want to call the methods of those names, you have to do:
David
David,
Thank for your reply, but I’m puzzled by it. Doesn’t the code in my
previous post make it clear that I’m dealing with instance variables?
The class instance initiates them, e.g., @log, and I’m trying to get
that with the run_log.log call. This is NOT an attempt to call a method.
I very carefully copied (I thought) the pattern I saw in several
authoritative sources, but it doesn’t work for me, which is nuts.
I hope this makes sense.
t.
–
Tom C., MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< [email protected] >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)
I’ve been staring at this for a couple of hours, and I cannot crack
the nut. This SHOULD work, but I’m obviously screwing up. Just
cannot see where. I’m carefully following several examples, but…I
cannot get access to my instance variables.
Here’s a stripped down version of the code -
>>
> of hours.
>
> Thanks Justin. Much appreciated.
>
> t.
Just remember that whenever you see
NoMethodError Exception: undefined method `…" for nil:NilClass
look at what variable you are calling the method on. Then figure out why
it is nil.
Take a look at ManageLog#open. The last expression is a call to puts,
which returns nil. You are setting the variable “run_log” to the
result of the call to open in the debugger, but that result is nil.
Then you try to call “log” on nil, thus the error.
-Justin
Well, nuts. That’s crystal clear. Man, it’s tough being a Ruby amateur,
when it 's not great fun, which it hasn’t been for a couple of hours.
Thanks Justin. Much appreciated.
t.
–
Tom C., MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< [email protected] >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)
the nut. This SHOULD work, but I’m obviously screwing up. Just
log = run_log.log
Thank for your reply, but I’m puzzled by it. Doesn’t the code in my
def initialize(name)
David
Sorry you got a partial copy of the code I sent. It rather sounded like
that was what happened. I DO appreciate that you responded so quickly.
You’ve certainly been very helpful to me on a number of occasions. (And
I require that help, at times, if I’m get anything much accomplished in
Ruby, in the time I have!).
Thanks.
Tom
–
Tom C., MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< [email protected] >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)
I’ve been staring at this for a couple of hours, and I cannot crack the
run_log = Manage_log.new( ‘logfile.txt’ ).open
Basically, given any expression that looks like this:
def initialize(name)
David
Sorry you got a partial copy of the code I sent. It rather sounded like that
was what happened.
I think I got it all (the bit I quoted was just a few lines of it),
but I surmised too quickly what your problem was. I’m STILL not sure
where attr_accessor fits in (You’re not calling it anywhere, are
you?) But it sounds like you got the problem resolved.
I DO appreciate that you responded so quickly. You’ve certainly
been very helpful to me on a number of occasions. (And I require
that help, at times, if I’m get anything much accomplished in Ruby,
in the time I have!).
Here’s a stripped down version of the code -
there. Ruby is interpreting log and logging_now as local variables. If
the explicit receiver to achieve the method call.
copied (I thought) the pattern I saw in several authoritative sources, but it
doesn’t work for me, which is nuts.
which are local variable assignments, and you’d mentioned
attr_accessor, so I assumed you had attr_accessor somewhere in a part
of the code you hadn’t posted. It’s a common error to do:
class C
attr_accessor :name
def initialize(name)
name = name # should be @name or self.name
end
end
so I surmised that that was what was going on. Oh well – can’t hurt
to see that particular potential problem anyway