aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-01-29 05:14:31 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-01-29 05:14:31 +0000
commit708a982cb493838cac25c575b14afd20aadba818 (patch)
treecbc2b336ac926526afbc094278179bff2ae31327 /lib
parentf54b960d30cc45d0f7592a49868a5fae4feab9e3 (diff)
downloadruby-708a982cb493838cac25c575b14afd20aadba818.tar.gz
erb.rb: duplicated magic comments [Fix GH-1229]
* lib/erb.rb (ERB#def_method): insert def line just before the first non-comment and non-empty line, not to leave duplicated and stale magic comments. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53684 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/erb.rb5
1 files changed, 2 insertions, 3 deletions
diff --git a/lib/erb.rb b/lib/erb.rb
index 2e9fad98b4..7c22ec2efa 100644
--- a/lib/erb.rb
+++ b/lib/erb.rb
@@ -905,10 +905,9 @@ class ERB
# erb.def_method(MyClass, 'render(arg1, arg2)', filename)
# print MyClass.new.render('foo', 123)
def def_method(mod, methodname, fname='(ERB)')
- src = self.src
- magic_comment = "#coding:#{@encoding}\n"
+ src = self.src.sub(/^(?!#|$)/) {"def #{methodname}\n"} << "\nend\n"
mod.module_eval do
- eval(magic_comment + "def #{methodname}\n" + src + "\nend\n", binding, fname, -2)
+ eval(src, binding, fname, -1)
end
end