From: James Edward Gray II Date: 2006-03-08T22:50:36+09:00 Subject: Re: newbie question about scope, variables, declarations of variables and option strict (as in perl) 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 # some code end #some code continues func > What I am asking is, what is scope of log? It's a local variable, scoped to the file it is defined in. It would not be available inside class, module, or method definitions though, because they are not closures. > What kind of variable is it? Local. > It is the local or instance variable of what, Object? To the file. > But what about log? How can I access it in a function without > making it global? You could pass it as a parameter, or make it an instance variable, as shown above. > Is there a way to make variables local to a file as perl does with > "my". This is how it functions. > Is there a strict option that prevents unintended variable creation > because > of typos. Is there a way force predeclaration of variables? You must assign to a local before you can use it in Ruby. That's why you got the error. ;) James Edward Gray II