Back to Blog

Ruby 2.6 adds Binding#source_location

on July 24, 2018
This blog is part of our Ruby 2.6 series.

Ruby 2.6.0 was released on Dec 25, 2018.

Before Ruby 2.6, if we want to know file name with location and line number of source code, we would need to use Binding#eval .

1binding.eval('[__FILE__, __LINE__]')
2=> ["/Users/taha/blog/app/controllers/application_controller", 2]

Ruby 2.6 adds more readable method Binding#source_location to achieve similar result.

2=> ["/Users/taha/blog/app/controllers/application_controller", 2]

Here is relevant commit and discussion for this change.

The Chinese version of this blog is available here.

You might also like

If you liked this blog post, check out similar ones from BigBinary