[前][次][番号順一覧][スレッド一覧]

ruby-changes:41610

From: nobu <ko1@a...>
Date: Fri, 29 Jan 2016 14:13:35 +0900 (JST)
Subject: [ruby-changes:41610] nobu:r53684 (trunk): erb.rb: duplicated magic comments [Fix GH-1229]

nobu	2016-01-29 14:14:31 +0900 (Fri, 29 Jan 2016)

  New Revision: 53684

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=53684

  Log:
    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.

  Modified files:
    trunk/ChangeLog
    trunk/lib/erb.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 53683)
+++ ChangeLog	(revision 53684)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Jan 29 14:13:28 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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@j...>
 
 	* lib/erb.rb (ERB#set_eoutvar): explicitly make mutable string as
Index: lib/erb.rb
===================================================================
--- lib/erb.rb	(revision 53683)
+++ lib/erb.rb	(revision 53684)
@@ -905,10 +905,9 @@ class ERB https://github.com/ruby/ruby/blob/trunk/lib/erb.rb#L905
   #   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
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]