From: James Edward Gray II Date: 2006-03-09T00:07:01+09:00 Subject: Re: newbie question about scope, variables, declarations of variables and option strict (as in perl) 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 Neo:~/Desktop$ cat test.log # Logfile created on Wed Mar 08 09:04:50 CST 2006 by logger.rb/1.5.2.7 D, [2006-03-08T09:04:50.196373 #5517] DEBUG -- : a statement James Edward Gray II