From: marcus Date: 2006-02-12T07:57:48+09:00 Subject: Re: Adding variables to a binding Caleb Clausen skrev: > On 2/11/06, marcus wrote: > > How about this instead: > > def outerscope > vars={} > innerscope(vars) > p vars[:foo],vars[:bar],vars[:baz] > end > > def innerscope(vars) > vars[:foo]=vars[:bar]=vars[:baz]=1 > end > The problem is that ERB#result(binding) takes a binding so I need the binding. The templates used in this case relies on Rails rules (member variables in a controller are available in the ERB template) and I need to create a binding containing everything from the controller scope (and then add the new needed stuff from the model). What about passing a block from outer scope and call it from inner scope and pass in a Hash with variables from the inner scope, then loop over the variables and add those as instance members (using instance_eval), create the binding (inside the block) and then invoke ERB.result. Could that work? /Marcus