From: takashikkbn@... Date: 2017-05-19T15:56:23+00:00 Subject: [ruby-core:81287] [Ruby trunk Feature#8631] Add a new method to ERB to allow assigning the local variables from a hash Issue #8631 has been updated by k0kubun (Takashi Kokubun). I found that my suggestion is a little hard to implement to avoid argument modification. It got a little ugly https://github.com/ruby/ruby/pull/1618/commits/ed1c1e520eec6cb96f1eae88bef2fa4ac54a3e6c. Anyway, currently we have 3 possible choices. 1. Proposed one (implementation is suggested by nobu): ERB.new(*).result({ foo: bar }) 2. Seki-san's patch (erb_with_hash): ERB.new(*).result_with_hash({ foo: bar }) 3. My suggestion: ERB.new(*).result(locals: { foo: bar }) From user's point of view, 1 is okay but a little confusing that it can take multiple types in the same argument, 2 is good but a name is long and 3 is the best. From maintainer's point of view, 1 is okay, 2 is the best and 3 is a little hard. So all of them have trade-offs. While I feel it's overkill to make it capable of having both Binding and Hash as arguments, I personally want to introduce 3 because it's easy to use and not confusing. I want your opinions about this. ---------------------------------------- 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-64956 * Author: rosenfeld (Rodrigo Rosenfeld Rosas) * Status: Assigned * 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: