From: ara howard Date: 2008-03-12T00:48:03+09:00 Subject: Re: setting local variables via eval On Mar 11, 2008, at 12:23 AM, Joel VanderWerf wrote: > ara howard wrote: >> http://drawohara.com/post/28514698 > > Nice hack, as usual :) > > Isn't > > class Object > def scope > lambda{ } > end > end > > enough? You don't need to return binding from the lambda, AFAICT. > The lambda never gets called. that's what i head originally - but blows up in 1.9 which requires a binding > > > Also, an alternative to mucking with ObjectSpace: > > Thread.current[:val] = v > definition = "#{ var } = Thread.current[:val]" > > in place of > > value = "ObjectSpace._id2ref #{ v.object_id }" > definition = "#{ var } = #{ value }" > > Of course, the value of Thread.current[:val] should be saved and > restored. Maybe this makes the hack jruby friendly. > oh very nice. yeah, pushing and popping from Thread.current is very good > There is one case in which the double_quoted_heredoc is not > hygienic, when a line of @template begins with __template__: > > view2 = View.new '__template__' > view3 = View.new view2.render > puts view3.render > > But I don't see any hygienic solution (indenting and using <<- > doesn't work, because the interpolated strings might have line > breaks). Maybe ruby needs a heredoc variant that runs to eof. > yes. in real code i generate the hdoc in a loop roughly like so loop { hdoc = "__a #{ rand(2**30).to_i }__b#{ rand(2**30).to_i }__c#{ rand(2**30).to_i }__" break unless template =~ Regexp.escape(hdoc) } etc great suggestions - the jruby/Thread.current esp. thx. a @ http://drawohara.com/ -- sleep is the best meditation. h.h. the 14th dalai lama