From: Robert Dober Date: 2008-03-11T20:28:32+09:00 Subject: Re: setting local variables via eval On Tue, Mar 11, 2008 at 5:20 AM, ara howard wrote: > > thought some here might appreciate this > > http://drawohara.com/post/28514698 > > kind regards > > a @ http://codeforpeople.com/ > -- > share your knowledge. it's a way to achieve immortality. > h.h. the 14th dalai lama > > > > Ara Obviously I miss something, but I have the feeling that this simplification still works, which use cases did I miss? The idea is crazy of course :) class View def initialize template @template = template end def render locals = {} context = binding locals.each do |k, v| definition = "#{ k } = #{ v }" eval definition, context end double_quoted_heredoc = ['<<__template__', @template, '__template__'].join("\n") eval double_quoted_heredoc, context end end view = View.new ' #{ x + y } ' puts view.render(:x => 40, :y => 2) #=> 42 Cheers Robert -- http://ruby-smalltalk.blogspot.com/ --- Whereof one cannot speak, thereof one must be silent. Ludwig Wittgenstein