From f8ecb823a0705eda22f845abea38fc065ecc3ab9 Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 28 Nov 2015 05:26:16 +0000 Subject: ripper/core.rb: dispatch alias * ext/ripper/lib/ripper/core.rb: alias same methods instead of eval for each events. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52774 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/ripper/lib/ripper/core.rb | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'ext/ripper') diff --git a/ext/ripper/lib/ripper/core.rb b/ext/ripper/lib/ripper/core.rb index 637a72f4ad..de8042f444 100644 --- a/ext/ripper/lib/ripper/core.rb +++ b/ext/ripper/lib/ripper/core.rb @@ -29,16 +29,21 @@ class Ripper 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 # 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 -- cgit v1.2.3