From: Christoph Date: 2002-06-06T22:12:12+09:00 Subject: Re: eval and local variable "ts" wrote in message .... > Not for me, this mean that since you understand whats going on anyway;-) > > * at compile type no local variable with the name 'foo' was defined > * at run time, no method with the name `foo' was defined The difference of compile and runtime is blurred (in my mind at least;-) and may explain the difficulties some people (including myself) have in understanding visibility rules of local variables. For example, I find it curious that Ruby raises a NameError when a variable name is used before being declared, even so the interpreter seems to have complete knowledge of all local_variable (that are and will be) declared in the current scope. --- p local_variables begin x = (eval "foo").nil? # doesn't raises a NameError since `foo' is declared # in the rescue clause p foo # raises a NameError since `foo' is not declared yet. rescue => mes p mes foo = 'bar' end p x,foo p local_variables begin x = eval "foo" p foo rescue => mes p mes foo = 'bar' end p x,foo # ["x", "mes", "foo"] # #> # true # "bar" --- and for good measure the eval version ... --- eval %{ p local_variables begin x = (eval "foo").nil? # already raises a NameError ... p foo rescue => mes p mes foo = 'bar' end p x,foo # curiously this does not raise an `x' NameError } # results in # [] # #> # nil # "bar" --- /Christoph