Ruby's `__LINE__`
Debugging a tough problem, with terse, unhelpful error messages? Sometimes puts
driven development can only take you so far.
A corner of Ruby I sometimes forget about are the double-underscore methods on Object
. Today I learned a new one: __LINE__
.
Here it is in the console:
2.1.0 :001 > puts __LINE__
1
=> nil
2.1.0 :002 > puts __LINE__
2
=> nil
2.1.0 :003 > puts __LINE__
3
=> nil
Try putting this above and below code you think might be causing an issue.
A new tool for my debugging toolbox. 🔨
h/t Brian Dunn
Tweet