From: dblack@... Date: 2006-03-09T00:38:21+09:00 Subject: Re: newbie question about scope, variables, declarations of variables and option strict (as in perl) Hi -- On Thu, 9 Mar 2006, James Edward Gray II wrote: > On Mar 8, 2006, at 8:39 AM, dblack@wobblini.net wrote: > >> Hi -- >> >> On Wed, 8 Mar 2006, James Edward Gray II wrote: >> >>> On Mar 8, 2006, at 3:01 AM, Talha Oktay wrote: >>> >>>> When I qualify log with $ as >>>> $log, it becomes global and I no longer receive error. I have tried it >>>> qualifying with @ etc. but the received the same error. >>> >>> No, this works too (after you fix your Logger constructor call): >>> >>> require 'logger' >>> >>> @log = Logger.new("test.log") #some other logger settings are ignored. >>> >>> def func >>> @log.debug "a statement" # error is reported here when func is called >>> below >> >> That's a different @log from the one you assigned to, though. > > I'm not sure why you say this, but you're wrong. ;) Here's the proof: > > Neo:~/Desktop$ ls > log.rb > Neo:~/Desktop$ cat log.rb > require 'logger' > > @log = Logger.new("test.log") #some other logger settings are ignored. > p @log.object_id > > def func > @log.debug "a statement" # error is reported here when func is called below > p @log.object_id > # some code > end > > #some code continues > func > Neo:~/Desktop$ ruby log.rb > 923180 > 923180 Weird. I guess Logger does something bizarre in its constructor. David -- David A. Black (dblack@wobblini.net) Ruby Power and Light, LLC (http://www.rubypowerandlight.com) "Ruby for Rails" chapters now available from Manning Early Access Program! http://www.manning.com/books/black