Issue #8631 has been updated by k0kubun (Takashi Kokubun).


> Or maybe ERB.new(str, locals: {a: b}).result?

For this case, it would have the same problem as ERB.new(str).result(locals: {a: b}) because it can have both binding and locals. In that case, adding locals to given binding is hard to maintain. Also, if we want to avoid the situation, raising error for that case does not seem a good idea (method should be separated in that case, especially for "3").

> I'm just not sure which name would be best. I like result_with_hash, but it could be result_from_locals or result_from_hash.

Then, the remaining problem is only the name of result_with_hash counterpart. Possible choices are:

- result_with_hash
- result_from_locals
- result_from_hash

What this method does is "rendering result with a context that given local variables are set". It's not result derived from only local variables. While "locals" is longer than "hash", it describes not type of argument but its actual content.

So I prefer "result_with_locals" ("render_with_locals" may be better but it should be unified with "result"). If you use the method with that name, I'm okay to add that.

----------------------------------------
Feature #8631: Add a new method to ERB to allow assigning the local variables from a hash
https://bugs.ruby-lang.org/issues/8631#change-65011

* Author: rosenfeld (Rodrigo Rosenfeld Rosas)
* Status: Feedback
* Priority: Normal
* Assignee: k0kubun (Takashi Kokubun)
* Target version: 2.5
----------------------------------------
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 }


---Files--------------------------------
feature-8631.pdf (27.7 KB)


-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>