Getting current line of code in Ruby

前端 未结 1 1289
长发绾君心
长发绾君心 2021-01-04 02:16

Crazy thought today.

Is there any way to grab the line number that code has been executed on?

Logger.info \"I was run on line #{get_line_number}\"


        
相关标签:
1条回答
  • 2021-01-04 03:04

    You can use __LINE__ variable. See this https://stackoverflow.com/a/2496240/100466 answer also.

    0 讨论(0)
提交回复
热议问题