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

ruby-changes:40695

From: nobu <ko1@a...>
Date: Sat, 28 Nov 2015 14:26:36 +0900 (JST)
Subject: [ruby-changes:40695] nobu:r52774 (trunk): ripper/core.rb: dispatch alias

nobu	2015-11-28 14:26:16 +0900 (Sat, 28 Nov 2015)

  New Revision: 52774

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

  Log:
    ripper/core.rb: dispatch alias
    
    * ext/ripper/lib/ripper/core.rb: alias same methods instead of
      eval for each events.

  Modified files:
    trunk/ext/ripper/lib/ripper/core.rb
Index: ext/ripper/lib/ripper/core.rb
===================================================================
--- ext/ripper/lib/ripper/core.rb	(revision 52773)
+++ ext/ripper/lib/ripper/core.rb	(revision 52774)
@@ -29,16 +29,21 @@ class Ripper https://github.com/ruby/ruby/blob/trunk/ext/ripper/lib/ripper/core.rb#L29
 
   private
 
+  def _dispatch_0() nil end
+  def _dispatch_1(a) a end
+  def _dispatch_2(a, b) a end
+  def _dispatch_3(a, b, c) a end
+  def _dispatch_4(a, b, c, d) a end
+  def _dispatch_5(a, b, c, d, e) a end
+  def _dispatch_6(a, b, c, d, e, f) a end
+  def _dispatch_7(a, b, c, d, e, f, g) a end
+
   #
   # Parser Events
   #
 
   PARSER_EVENT_TABLE.each do |id, arity|
-    module_eval(<<-End, __FILE__, __LINE__ + 1)
-      def on_#{id}(#{ ('a'..'z').to_a[0, arity].join(', ') })
-        #{arity == 0 ? 'nil' : 'a'}
-      end
-    End
+    alias_method "on_#{id}", "_dispatch_#{arity}"
   end
 
   # This method is called when weak warning is produced by the parser.
@@ -60,11 +65,7 @@ class Ripper https://github.com/ruby/ruby/blob/trunk/ext/ripper/lib/ripper/core.rb#L65
   #
 
   SCANNER_EVENTS.each do |id|
-    module_eval(<<-End, __FILE__, __LINE__ + 1)
-      def on_#{id}(token)
-        token
-      end
-    End
+    alias_method "on_#{id}", :_dispatch_1
   end
 
 end

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

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