Or, if you want an uber-one-liner:
@scope_object.send(:extend, @options[:locals].inject(Module.new) { |m,
k, v| m.send(:define_method, k) { v } })
Is it just me, or could Haml use some code-cleanup?
Nick
On Apr 12, 6:34 pm, "Nathan Weizenbaum" <[EMAIL PROTECTED]> wrote:
> You're right, it should be like that. I don't know how it snuck through.
> I'll fix it later today.
>
> - Nathan
>
> On 4/12/07, Nick Howell <[EMAIL PROTECTED]> wrote:
>
>
>
> > In Haml::Engine#render:
> > <pre>
> > 176 def render(scope = Object.new, &block)
> > 177 @scope_object = scope
> > 178 @buffer = Haml::Buffer.new(@options)
> > 179
> > 180 local_assigns = @options[:locals]
> > 181
> > 182 # Get inside the view object's world
> > 183 @scope_object.instance_eval do
> > 184 # Set all the local assigns
> > 185 local_assigns.each do |key,val|
> > 186 self.class.send(:define_method, key) { val }
> > 187 end
> > 188 end
> > </pre>
>
> > Notice that scope and @scope_object are, by default, Objects. When
> > local_assigns are...assigned...the Object class has new methods
> > defined on it. This is *bad*.
>
> > I suggest that we replace it with this:
> > <pre>
> > m = Module.new
> > locals_assigns.each { |k, v| m.send(:define_method, k) { m } }
> > @scope_object.send(:extend, m)
> > </pre>
>
> > Thoughts?
>
> > Nick
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Haml" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/haml?hl=en
-~----------~----~----~----~------~----~------~--~---