From: Christoph Date: 2002-06-01T14:27:36+09:00 Subject: Re: possible bug: stack dump with <<-String, #{...} and large loops From: ts decoux@moulon.inra.fr .... C> def aa(x) > C> if x > C> eval "p a" # premonition > C> end > C> a = 1 > C> end > This is normal : when it has compiled the > def it has found a local > variable `a', and #eval just retrieve this It does not really retrieve it - it is just telling Ruby to interpret ``a'' as an initialized local variable. Without the `eval part' you would get a NameError, this difference is really surprising (to me at least;-). It is at least interesting that running the free form (no method) of the same Ruby snippet --- if x eval "p a" # no premonition end a = 1 --- also raises a NameError. .... > C> def aa > C> "#{}" > C> eval "a = 1" > C> p "#{defined? a}" > C> end > Well, this is a special case (work only with a few version of ruby) where > the execution of "#{}" will make all *new* variables dynamic (local > in-block). eval "a = 1" in this case create a *new* variable and in this > case the variable is dynamic Thanks for this explanation. C> def bb C> "#{}" C> eval "b = 1" C> p "#{defined? b}" C> b = 2 # premonition C> end > Same than the first example, `b' was found when ruby has compiled the def > #eval just retrieve this variable so basically it uses the `insight' (that `b' is a local variable and not dynamic variable ) gained at the end of the method body and to reinterpret the previous lines in that new light? .... /Christoph