Skip to content

Commit

Permalink
Move IRB::TOPLEVEL_BINDING from exe/irb to lib/irb/workspace.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
aycabta committed Sep 9, 2021
1 parent a5c3f6b commit e736a77
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 3 deletions.
1 change: 0 additions & 1 deletion bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
require "bundler/setup"
require_relative "../lib/irb"

IRB::TOPLEVEL_BINDING = binding
IRB.start(__FILE__)
1 change: 0 additions & 1 deletion exe/irb
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@

require "irb"

IRB::TOPLEVEL_BINDING = binding
IRB.start(__FILE__)
2 changes: 2 additions & 0 deletions lib/irb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,8 @@ def handle_exception(exc)
lines = lines.reverse if order == :bottom
lines.map{ |l| l + "\n" }.join
}
# The "<top (required)>" in "(irb)" may be the top level of IRB so imitate the main object.
message = message.gsub(/\(irb\):(?<num>\d+):in `<(?<frame>top \(required\))>'/) { "(irb):#{$~[:num]}:in `<main>'" }
puts message
end
print "Maybe IRB bug!\n" if irb_bug
Expand Down
3 changes: 2 additions & 1 deletion lib/irb/workspace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

require "delegate"

IRB::TOPLEVEL_BINDING = binding
module IRB # :nodoc:
class WorkSpace
# Creates a new workspace.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e736a77

Please sign in to comment.