From: "T. Onoma" Date: 2003-11-24T17:35:46+09:00 Subject: Controlled block variables (was: open-uri patch, added progress_proc hook) In considering some of the things we've been discussing related to the open-uri hook, duck_typing, singletons, and block scope.... I have to throw in evals, and how they work. I tend to use eval quite often it seems, at least in my more interesting "ruby research" coding. One of the annoyances that I frequently run into is the need to pull variables from the current scope into the eval block. Obviosuly to do this one has to pass eval a string wilth "#{x}" substituions in it, or concatinations of strings, "..." + x + "...". In fact you HAVE to do the later if the eval will have its only substitions. Ie. "..." + ' "#{c}" ' + "...". But this also causes whole literals to be placed into the evalutaion. Eg. a = [1,2,3] eval "[#{a.join(',')}]" What would really make eval much more convenient is if it had some type of scope "holes" cutting through to the current scope. Of course this would require a special meta-syntax, but it should be possible. In fact, I imagine we could jsut use the current string substitution for this, since # represents a remark anyway. #{ would be a special token. For example: x = 'hello' eval { x = 1; p "#{x}" } # => "1" (as expected) eval { x = 1; p #{x} } # => "hello" (rabbit hole) Would something like this be possible --eval with closure? Even if a different syntax were needed, this would be a great advantage. -t0