summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/irb/workspace.rb2
-rwxr-xr-xlibexec/irb1
-rw-r--r--test/irb/test_workspace.rb10
3 files changed, 13 insertions, 0 deletions
diff --git a/lib/irb/workspace.rb b/lib/irb/workspace.rb
index 78d434d106..8157e21644 100644
--- a/lib/irb/workspace.rb
+++ b/lib/irb/workspace.rb
@@ -57,6 +57,8 @@ EOF
__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)
+ # This is to avoid RubyGems' local variables (see issue #17623)
@binding = TOPLEVEL_BINDING.dup
end
end
diff --git a/libexec/irb b/libexec/irb
index c64ee85fbd..7cd24482da 100755
--- a/libexec/irb
+++ b/libexec/irb
@@ -8,4 +8,5 @@
require "irb"
+IRB::TOPLEVEL_BINDING = binding
IRB.start(__FILE__)
diff --git a/test/irb/test_workspace.rb b/test/irb/test_workspace.rb
index a39bea2050..61653486a1 100644
--- a/test/irb/test_workspace.rb
+++ b/test/irb/test_workspace.rb
@@ -80,6 +80,16 @@ module TestIRB
assert_equal(nil, workspace.code_around_binding)
end
+
+ def test_toplevel_binding_local_variables
+ bug17623 = '[ruby-core:102468]'
+ bundle_exec = ENV.key?('BUNDLE_GEMFILE') ? ['-rbundler/setup'] : []
+ status = assert_in_out_err(bundle_exec + ['-W0', '-e', <<~RUBY , '--', '-f', '--'], 'binding.local_variables', /\[:_\]/, [], bug17623)
+ version = 'xyz' # typical rubygems loading file
+ load('./exe/irb')
+ RUBY
+ end
+
private
def with_script_lines