From: "David A. Black" Date: 2009-01-21T11:17:35+09:00 Subject: Re: cannot get attr_accessor to work 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 A. Black / Ruby Power and Light, LLC Ruby/Rails consulting & training: http://www.rubypal.com Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2) http://www.wishsight.com => Independent, social wishlist management!