Skip to content

Commit

Permalink
Change path passed to eval, don't change irb_path.
Browse files Browse the repository at this point in the history
  • Loading branch information
tompng committed Feb 12, 2024
1 parent 91cc476 commit eaa11a4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 0 additions & 2 deletions lib/irb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1531,8 +1531,6 @@ def irb(show_code: true)
debugger_irb = IRB.instance_variable_get(:@debugger_irb)

irb_path = File.expand_path(source_location[0])
# We need to change the irb_path to distinguish source_location of method defined in the actual file and method defined in irb session.
irb_path = "#{irb_path}(#{IRB.conf[:IRB_NAME]})" if File.exist?(irb_path)

if debugger_irb
# If we're already in a debugger session, set the workspace and irb_path for the original IRB instance
Expand Down
7 changes: 5 additions & 2 deletions lib/irb/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -555,9 +555,12 @@ def evaluate(line, line_no) # :nodoc:
IRB.set_measure_callback
end

# We need to use differente path to distinguish source_location of method defined in the actual file and method defined in irb session.
eval_path = File.exist?(irb_path) ? "#{irb_path}(#{IRB.conf[:IRB_NAME]})" : irb_path

if IRB.conf[:MEASURE] && !IRB.conf[:MEASURE_CALLBACKS].empty?
last_proc = proc do
result = @workspace.evaluate(line, irb_path, line_no)
result = @workspace.evaluate(line, eval_path, line_no)
end
IRB.conf[:MEASURE_CALLBACKS].inject(last_proc) do |chain, item|
_name, callback, arg = item
Expand All @@ -568,7 +571,7 @@ def evaluate(line, line_no) # :nodoc:
end
end.call
else
result = @workspace.evaluate(line, irb_path, line_no)
result = @workspace.evaluate(line, eval_path, line_no)
end

set_last_value(result)
Expand Down

0 comments on commit eaa11a4

Please sign in to comment.