diff --git a/ChangeLog b/ChangeLog index 73371bc898..d1bf010e8d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Fri Jan 29 14:13:28 2016 Nobuyoshi Nakada + + * 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. + Fri Jan 29 11:13:33 2016 Jeremy Evans * lib/erb.rb (ERB#set_eoutvar): explicitly make mutable string as 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