Skip to content

Commit

Permalink
Change context-mode's default to new mode 4.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
marcandre committed Nov 20, 2020
1 parent af40849 commit 2858f83
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/irb/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def IRB.init_config(ap_path)
@CONF[:PROMPT_MODE] = (STDIN.tty? ? :DEFAULT : :NULL)
@CONF[:AUTO_INDENT] = true

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

@CONF[:LC_MESSAGES] = Locale.new
Expand Down
4 changes: 3 additions & 1 deletion lib/irb/workspace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ def initialize(*main)
end
@binding = BINDING_QUEUE.pop

when 3 # binding in function on TOPLEVEL_BINDING(default)
when 3 # binding in function on TOPLEVEL_BINDING
@binding = eval("self.class.send(:remove_method, :irb_binding) if defined?(irb_binding); private; def irb_binding; binding; end; irb_binding",
TOPLEVEL_BINDING,
__FILE__,
__LINE__ - 3)
when 4 # binding is a copy of TOPLEVEL_BINDING (default)
@binding = TOPLEVEL_BINDING.dup
end
end

Expand Down

0 comments on commit 2858f83

Please sign in to comment.