On Tue, Mar 11, 2008 at 4:52 PM, ara howard <ara.t.howard / gmail.com> wrote: > > On Mar 11, 2008, at 5:28 AM, Robert Dober wrote: > > > 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 '<body> #{ x + y } </body>' > > puts view.render(:x => 40, :y => 2) #=> <body> 42 </body> > > > > Cheers > > Robert > > > cfp2:~ > cat a.rb > require 'yaml' > > locals = { > 'K' => 'or any thing else really', > 'k' => %w( list of words ), > > } > > context = binding context = binding has to be in the render_locals method, so I fail to understand the point of the example, if eval 'x=1', binding worked on the top level this thread would not even exist, right? <skipped rest of example> Robert -- http://ruby-smalltalk.blogspot.com/ --- Whereof one cannot speak, thereof one must be silent. Ludwig Wittgenstein