From: Tom Cloyd Date: 2009-01-21T11:26:52+09:00 Subject: Re: cannot get attr_accessor to work David A. Black wrote: > Hi -- > > On Wed, 21 Jan 2009, 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 - >> >> # SetNet.rb >> >> def main >> # Set up logging >> run_log = Manage_log.new( 'logfile.txt' ).open >> log = run_log.log >> logging_now = run_log.lgg # @logging_now = false > > 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: > > self.log = run_log.log > self.logging_now = run_log.lgg > > Basically, given any expression that looks like this: > > var = value > > the parser interprets var as a local variable name. So you have to add > the explicit receiver to achieve the method call. > > > 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 Cloyd, MS MA, LMHC - Private practice Psychotherapist Bellingham, Washington, U.S.A: (360) 920-1226 << tc@tomcloyd.com >> (email) << TomCloyd.com >> (website) << sleightmind.wordpress.com >> (mental health weblog) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~