Skip to content

Commit e736a77

Browse files
committed
Move IRB::TOPLEVEL_BINDING from exe/irb to lib/irb/workspace.rb
1 parent a5c3f6b commit e736a77

File tree

4 files changed

+4
-3
lines changed

4 files changed

+4
-3
lines changed

bin/console

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@
33
require "bundler/setup"
44
require_relative "../lib/irb"
55

6-
IRB::TOPLEVEL_BINDING = binding
76
IRB.start(__FILE__)

exe/irb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@
88

99
require "irb"
1010

11-
IRB::TOPLEVEL_BINDING = binding
1211
IRB.start(__FILE__)

lib/irb.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,8 @@ def handle_exception(exc)
669669
lines = lines.reverse if order == :bottom
670670
lines.map{ |l| l + "\n" }.join
671671
}
672+
# The "<top (required)>" in "(irb)" may be the top level of IRB so imitate the main object.
673+
message = message.gsub(/\(irb\):(?<num>\d+):in `<(?<frame>top \(required\))>'/) { "(irb):#{$~[:num]}:in `<main>'" }
672674
puts message
673675
end
674676
print "Maybe IRB bug!\n" if irb_bug

lib/irb/workspace.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
require "delegate"
1414

15+
IRB::TOPLEVEL_BINDING = binding
1516
module IRB # :nodoc:
1617
class WorkSpace
1718
# Creates a new workspace.
@@ -57,7 +58,7 @@ def initialize(*main)
5758
__FILE__,
5859
__LINE__ - 3)
5960
when 4 # binding is a copy of TOPLEVEL_BINDING (default)
60-
# Note that this will typically be IRB::TOPLEVEL_BINDING (see exe/irb)
61+
# Note that this will typically be IRB::TOPLEVEL_BINDING
6162
# This is to avoid RubyGems' local variables (see issue #17623)
6263
@binding = TOPLEVEL_BINDING.dup
6364
end

0 commit comments

Comments
 (0)