From: Justin Collins Date: 2009-01-21T11:42:42+09:00 Subject: Re: cannot get attr_accessor to work Tom Cloyd wrote: > Justin Collins wrote: >> Tom Cloyd wrote: >>> 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 - >>> >>> >>>> (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. >> >> -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. 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. -Justin