diff --git a/lib/irb/context.rb b/lib/irb/context.rb index e23285ad9..814a8bd4a 100644 --- a/lib/irb/context.rb +++ b/lib/irb/context.rb @@ -555,9 +555,6 @@ 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, eval_path, line_no) @@ -577,6 +574,14 @@ def evaluate(line, line_no) # :nodoc: set_last_value(result) end + private def eval_path + # We need to use differente path to distinguish source_location of method defined in the actual file and method defined in irb session. + if !defined?(@irb_path_existence) || @irb_path_existence[0] != irb_path + @irb_path_existence = [irb_path, File.exist?(irb_path)] + end + @irb_path_existence[1] ? "#{irb_path}(#{IRB.conf[:IRB_NAME]})" : irb_path + end + def inspect_last_value # :nodoc: @inspect_method.inspect_value(@last_value) end diff --git a/test/irb/test_context.rb b/test/irb/test_context.rb index a76152169..0fdd847a6 100644 --- a/test/irb/test_context.rb +++ b/test/irb/test_context.rb @@ -666,6 +666,15 @@ def test_lineno ], out) end + def test_eval_path + @context.irb_path = __FILE__ + assert_equal("#{__FILE__}(irb)", @context.send(:eval_path)) + @context.irb_path = 'file/does/not/exist' + assert_equal('file/does/not/exist', @context.send(:eval_path)) + @context.irb_path = "#{__FILE__}(irb)" + assert_equal("#{__FILE__}(irb)", @context.send(:eval_path)) + end + def test_build_completor verbose, $VERBOSE = $VERBOSE, nil original_completor = IRB.conf[:COMPLETOR]