From: nobu@... Date: 2017-02-06T13:45:32+00:00 Subject: [ruby-core:79458] [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 Nobuyoshi Nakada. Another implementation: ```diff diff --git a/lib/erb.rb b/lib/erb.rb index 9483711024..9813b4dc71 100644 --- a/lib/erb.rb +++ b/lib/erb.rb @@ -887,6 +887,11 @@ # code evaluation. # def result(b=new_toplevel) + if b.respond_to?(:each_pair) + x = new_toplevel + b.each_pair {|k, v| x.local_variable_set(k, v)} + b = x + end if @safe_level proc { $SAFE = @safe_level ``` ---------------------------------------- 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-62890 * Author: Rodrigo Rosenfeld Rosas * Status: Assigned * Priority: Normal * 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 } ---Files-------------------------------- feature-8631.pdf (27.7 KB) -- https://bugs.ruby-lang.org/ Unsubscribe: