Today I Learned

hashrocket A Hashrocket project

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__
 => nil
2.1.0 :002 > puts __LINE__
 => nil
2.1.0 :003 > puts __LINE__
 => 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

See More #ruby TILs
Looking for help? Each developer at Hashrocket has years of experience working with Ruby applications of all types and sizes. We're an active presence at Ruby conferences, have written some of the most popular gems, and have worked on many of the web's Ruby on Rails success stories. Contact us today to talk about your Ruby project.