Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

214
Views
¿Cómo encontrar la línea de código exacta donde se devuelve un rendimiento?
def test_method result = [] result << yield # How to get the line number of where next was invoked in this block puts caller[0] # Gives the line number of another_method result end def another_method a = 1 b = 2 test_method do next if a == 1 next if b == 200 end end

En el código anterior, el rendimiento devuelve el siguiente si a == 1 , ¿cómo obtener el número de línea del código fuente donde se invocó el siguiente en el bloque dado desde test_method?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Con fines de depuración, puede usar TracePoint para monitorear las líneas ejecutadas:

 # test.rb # 1 # 2 def test_method # 3 result = [] # 4 trace = TracePoint.new(:line) do |tp| # 5 p tp # 6 end # 7 trace.enable do # 8 result << yield # 9 end # 10 result # 11 end # 12 # 13 def another_method # 14 a = 1 # 15 b = 2 # 16 test_method do # 17 next if a == 1 # 18 next if b == 200 # 19 end # 20 end # 21 # 22 another_method # 23

Producción:

 #<TracePoint:line@test.rb:9 in `test_method'> #<TracePoint:line@test.rb:18 in `another_method'>
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!