Skip to content

Commit

Permalink
Respect parent command line arguments in nested IRB scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
nunosilva800 committed Jan 31, 2024
1 parent a641746 commit d1e2203
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
5 changes: 2 additions & 3 deletions lib/irb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1513,8 +1513,8 @@ class Binding
#
# See IRB for more information.
def irb(show_code: true)
# Setup IRB with the current file's path and no command line arguments
IRB.setup(source_location[0], argv: [])
# Setup IRB with the current file's path and current session command line arguments
IRB.setup(source_location[0], argv: IRB.conf[:ARGV])
# Create a new workspace using the current binding
workspace = IRB::WorkSpace.new(self)
# Print the code around the binding if show_code is true
Expand All @@ -1523,7 +1523,6 @@ def irb(show_code: true)
debugger_irb = IRB.instance_variable_get(:@debugger_irb)

irb_path = File.expand_path(source_location[0])

if debugger_irb
# If we're already in a debugger session, set the workspace and irb_path for the original IRB instance
debugger_irb.context.workspace = workspace
Expand Down
10 changes: 6 additions & 4 deletions lib/irb/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ def IRB.version

# initialize config
def IRB.setup(ap_path, argv: ::ARGV)
IRB.init_config(ap_path)
IRB.init_config(ap_path, argv: argv)
IRB.init_error
IRB.parse_opts(argv: argv)
IRB.parse_opts
IRB.run_config
IRB.load_modules

Expand All @@ -55,7 +55,7 @@ def IRB.setup(ap_path, argv: ::ARGV)
end

# @CONF default setting
def IRB.init_config(ap_path)
def IRB.init_config(ap_path, argv: ::ARGV)
# class instance variables
@TRACER_INITIALIZED = false

Expand All @@ -68,6 +68,7 @@ def IRB.init_config(ap_path)

@CONF[:IRB_NAME] = "irb"
@CONF[:IRB_LIB_PATH] = File.dirname(__FILE__)
@CONF[:ARGV] = argv.dup

@CONF[:RC] = true
@CONF[:LOAD_MODULES] = []
Expand Down Expand Up @@ -244,7 +245,8 @@ def IRB.init_error
end

# option analyzing
def IRB.parse_opts(argv: ::ARGV)
def IRB.parse_opts
argv = @CONF[:ARGV].dup || []
load_path = []
while opt = argv.shift
case opt
Expand Down
2 changes: 1 addition & 1 deletion lib/irb/workspace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def load_commands_to_main
main.extend ExtendCommandBundle
end

# Evaluate the given +statements+ within the context of this workspace.
# Evaluate the given +statements+ within the context of this workspace.
def evaluate(statements, file = __FILE__, line = __LINE__)
eval(statements, @binding, file, line)
end
Expand Down

0 comments on commit d1e2203

Please sign in to comment.