diff --git a/bin/console b/bin/console index 61cab6067..4405b2326 100755 --- a/bin/console +++ b/bin/console @@ -3,5 +3,4 @@ require "bundler/setup" require_relative "../lib/irb" -IRB::TOPLEVEL_BINDING = binding IRB.start(__FILE__) diff --git a/exe/irb b/exe/irb index 7cd24482d..c64ee85fb 100755 --- a/exe/irb +++ b/exe/irb @@ -8,5 +8,4 @@ require "irb" -IRB::TOPLEVEL_BINDING = binding IRB.start(__FILE__) diff --git a/lib/irb.rb b/lib/irb.rb index c22e6db03..665f67b94 100644 --- a/lib/irb.rb +++ b/lib/irb.rb @@ -669,6 +669,8 @@ def handle_exception(exc) lines = lines.reverse if order == :bottom lines.map{ |l| l + "\n" }.join } + # The "" in "(irb)" may be the top level of IRB so imitate the main object. + message = message.gsub(/\(irb\):(?\d+):in `<(?top \(required\))>'/) { "(irb):#{$~[:num]}:in `
'" } puts message end print "Maybe IRB bug!\n" if irb_bug diff --git a/lib/irb/workspace.rb b/lib/irb/workspace.rb index 8157e2164..2c4c40f34 100644 --- a/lib/irb/workspace.rb +++ b/lib/irb/workspace.rb @@ -12,6 +12,7 @@ require "delegate" +IRB::TOPLEVEL_BINDING = binding module IRB # :nodoc: class WorkSpace # Creates a new workspace. @@ -57,7 +58,7 @@ def initialize(*main) __FILE__, __LINE__ - 3) when 4 # binding is a copy of TOPLEVEL_BINDING (default) - # Note that this will typically be IRB::TOPLEVEL_BINDING (see exe/irb) + # Note that this will typically be IRB::TOPLEVEL_BINDING # This is to avoid RubyGems' local variables (see issue #17623) @binding = TOPLEVEL_BINDING.dup end