Ruby 3.3 リファレンスマニュアル

instance method TracePoint#lineno

lineno -> IntegerRuby 2.0.0 から[permalink][rdoc][edit]

発生したイベントの行番号を返します。

[EXCEPTION] RuntimeError:
イベントフックの外側で実行した場合に発生します。
def foo(ret)
  ret
end
trace = TracePoint.new(:call, :return) do |tp|
  tp.lineno
end
trace.enable
p foo 1
# => 1
# 3