diff options
author | k0kubun <k0kubun@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-05-25 15:38:25 +0000 |
---|---|---|
committer | k0kubun <k0kubun@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-05-25 15:38:25 +0000 |
commit | eb1652b57171f5af5b667010c1721d5d29c5a437 (patch) | |
tree | b4cf5f243c1c55672f7a9ea4b9b3431ab0dbc9bb /lib | |
parent | fd8df3ab3d935b4a201f9cb28598c95e4bb1ef14 (diff) | |
download | ruby-eb1652b57171f5af5b667010c1721d5d29c5a437.tar.gz |
erb.rb: Add ERB#result_with_hash
[ruby-core:55985] [Feature #8631] [fix GH-1623]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58891 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r-- | lib/erb.rb | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/erb.rb b/lib/erb.rb index 4c29553a53..f367e32a97 100644 --- a/lib/erb.rb +++ b/lib/erb.rb @@ -889,6 +889,16 @@ class ERB end end + # Render a template on a new toplevel binding with local variables specified + # by a Hash object. + def result_with_hash(hash) + b = new_toplevel + hash.each_pair do |key, value| + b.local_variable_set(key, value) + end + result(b) + end + ## # Returns a new binding each time *near* TOPLEVEL_BINDING for runs that do # not specify a binding. |