mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
f54b960d30
commit
708a982cb4
2 changed files with 8 additions and 3 deletions
|
@ -1,3 +1,9 @@
|
|||
Fri Jan 29 14:13:28 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* 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 <code@jeremyevans.net>
|
||||
|
||||
* lib/erb.rb (ERB#set_eoutvar): explicitly make mutable string as
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue