summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-22 08:08:31 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-22 08:08:31 +0000
commit161f4a511ad01c0e7f013b03aae6afd4c386b1df (patch)
tree8629683dbee51ed72310edf7463394a3d3e3bf60 /lib
parent84e462758de5e1992d5fc763766ff85628aec1c5 (diff)
erb.rb: shadow by keys
* lib/erb.rb (ERB#new_toplevel): shadow already defined local variables by block local variabes, not to overwrite them. [ruby-core:84390] [Bug #14215] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61411 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/erb.rb13
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/erb.rb b/lib/erb.rb
index a950aec84e..c616178507 100644
--- a/lib/erb.rb
+++ b/lib/erb.rb
@@ -889,7 +889,7 @@ class ERB
# Render a template on a new toplevel binding with local variables specified
# by a Hash object.
def result_with_hash(hash)
- b = new_toplevel
+ b = new_toplevel(hash.keys)
hash.each_pair do |key, value|
b.local_variable_set(key, value)
end
@@ -900,8 +900,15 @@ class ERB
# Returns a new binding each time *near* TOPLEVEL_BINDING for runs that do
# not specify a binding.
- def new_toplevel
- TOPLEVEL_BINDING.dup
+ def new_toplevel(vars = nil)
+ b = TOPLEVEL_BINDING
+ if vars
+ vars = vars.select {|v| b.local_variable_defined?(v)}
+ unless vars.empty?
+ return b.eval("tap {|;#{vars.join(',')}| break binding}")
+ end
+ end
+ b.dup
end
private :new_toplevel