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

ruby-changes:50938

From: nobu <ko1@a...>
Date: Sat, 14 Apr 2018 03:06:43 +0900 (JST)
Subject: [ruby-changes:50938] nobu:r63144 (trunk): irb.rb: hoist out handle_exception

nobu	2018-04-14 03:06:35 +0900 (Sat, 14 Apr 2018)

  New Revision: 63144

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

  Log:
    irb.rb: hoist out handle_exception

  Modified files:
    trunk/lib/irb.rb
Index: lib/irb.rb
===================================================================
--- lib/irb.rb	(revision 63143)
+++ lib/irb.rb	(revision 63144)
@@ -497,43 +497,47 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb.rb#L497
           rescue Exception => exc
           end
           if exc
-            if exc.backtrace && exc.backtrace[0] =~ /irb(2)?(\/.*|-.*|\.rb)?:/ && exc.class.to_s !~ /^IRB/ &&
-                !(SyntaxError === exc)
-              irb_bug = true
-            else
-              irb_bug = false
-            end
+            handle_exception(exc)
+          end
+        end
+      end
+    end
 
-            messages = []
-            lasts = []
-            levels = 0
-            if exc.backtrace
-              count = 0
-              exc.backtrace.each do |m|
-                m = @context.workspace.filter_backtrace(m) or next unless irb_bug
-                m = sprintf("%9d: from %s", (count += 1), m)
-                if messages.size < @context.back_trace_limit
-                  messages.push(m)
-                elsif lasts.size < @context.back_trace_limit
-                  lasts.push(m).shift
-                  levels += 1
-                end
-              end
-            end
-            attr = STDOUT.tty? ? ATTR_TTY : ATTR_PLAIN
-            print "#{attr[1]}Traceback#{attr[]} (most recent call last):\n"
-            unless lasts.empty?
-              puts lasts.reverse
-              printf "... %d levels...\n", levels if levels > 0
-            end
-            puts messages.reverse
-            messages = exc.to_s.split(/\n/)
-            print "#{attr[1]}#{exc.class} (#{attr[4]}#{messages.shift}#{attr[0, 1]})#{attr[]}\n"
-            puts messages.map {|s| "#{attr[1]}#{s}#{attr[]}\n"}
-            print "Maybe IRB bug!\n" if irb_bug
+    def handle_exception(exc)
+      if exc.backtrace && exc.backtrace[0] =~ /irb(2)?(\/.*|-.*|\.rb)?:/ && exc.class.to_s !~ /^IRB/ &&
+         !(SyntaxError === exc)
+        irb_bug = true
+      else
+        irb_bug = false
+      end
+
+      messages = []
+      lasts = []
+      levels = 0
+      if exc.backtrace
+        count = 0
+        exc.backtrace.each do |m|
+          m = @context.workspace.filter_backtrace(m) or next unless irb_bug
+          m = sprintf("%9d: from %s", (count += 1), m)
+          if messages.size < @context.back_trace_limit
+            messages.push(m)
+          elsif lasts.size < @context.back_trace_limit
+            lasts.push(m).shift
+            levels += 1
           end
         end
       end
+      attr = STDOUT.tty? ? ATTR_TTY : ATTR_PLAIN
+      print "#{attr[1]}Traceback#{attr[]} (most recent call last):\n"
+      unless lasts.empty?
+        puts lasts.reverse
+        printf "... %d levels...\n", levels if levels > 0
+      end
+      puts messages.reverse
+      messages = exc.to_s.split(/\n/)
+      print "#{attr[1]}#{exc.class} (#{attr[4]}#{messages.shift}#{attr[0, 1]})#{attr[]}\n"
+      puts messages.map {|s| "#{attr[1]}#{s}#{attr[]}\n"}
+      print "Maybe IRB bug!\n" if irb_bug
     end
 
     # Evaluates the given block using the given +path+ as the Context#irb_path

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

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