Feature #8631

Add a new method to ERB to allow assigning the local variables from a hash

Added by Rodrigo Rosenfeld Rosas 10 months ago. Updated 9 months ago.

Assignee:Masatoshi Seki
Target version:-


It would be interesting if ERB could allow a hash instead of a binding for processing the template.

We wouldn't have to do hacks like:

b = OpenStruct.new(hash).instance_eval{ binding }


#1 Updated by Shota Fukumori 9 months ago

  • Status changed from Open to Assigned
  • Assignee set to Masatoshi Seki

Assigning to erb maintainer;

IMO, I recommend you to show example mock-code that uses your proposal, to show what interface (API) do you want :)

#2 Updated by Rodrigo Rosenfeld Rosas 9 months ago

I didn't propose an API because I don't really care about the API as long as it allows us to provide a hash instead of a binding.

If you want an example API that would satisfy me, I'd be happy if we used the same API (ERB#result). If the argument is a hash, use the keys as the local variables and the values as the variable values.

#3 Updated by Rodrigo Rosenfeld Rosas 9 months ago

You can see here how often people want to use a hash to render an ERB template:


And there's no quick way for performing this common procedure. The quickest one seems to be using OpenStruct for that...

Also available in: Atom PDF