OVERTONE
OVERTONE

Reputation: 12187

Getting current line of code in Ruby

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}"

Upvotes: 18

Views: 5584

Answers (1)

Waseem
Waseem

Reputation: 8402

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

Upvotes: 31

Related Questions