Skip to content

Commit 25c731c

Browse files
committed
Change context-mode's default to new mode 4.
This new mode uses a copy of the TOPLEVEL_BINDING. This is compatible with refinements (contrary to mode 3), while keeping nested IRB sessions separate
1 parent 5c6f18e commit 25c731c

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

lib/irb/init.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def IRB.init_config(ap_path)
108108
@CONF[:PROMPT_MODE] = (STDIN.tty? ? :DEFAULT : :NULL)
109109
@CONF[:AUTO_INDENT] = true
110110

111-
@CONF[:CONTEXT_MODE] = 3 # use binding in function on TOPLEVEL_BINDING
111+
@CONF[:CONTEXT_MODE] = 4 # use a copy of TOPLEVEL_BINDING
112112
@CONF[:SINGLE_IRB] = false
113113

114114
@CONF[:LC_MESSAGES] = Locale.new

lib/irb/workspace.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,13 @@ def initialize(*main)
5151
end
5252
@binding = BINDING_QUEUE.pop
5353

54-
when 3 # binding in function on TOPLEVEL_BINDING(default)
54+
when 3 # binding in function on TOPLEVEL_BINDING
5555
@binding = eval("self.class.remove_method(:irb_binding) if defined?(irb_binding); private; def irb_binding; binding; end; irb_binding",
5656
TOPLEVEL_BINDING,
5757
__FILE__,
5858
__LINE__ - 3)
59+
when 4 # binding is a copy of TOPLEVEL_BINDING (default)
60+
@binding = TOPLEVEL_BINDING.dup
5961
end
6062
end
6163

0 commit comments

Comments
 (0)