This blog is part of our Ruby 2.6 series.
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 (Link is not available) .
binding.eval('[__FILE__, __LINE__]')
=> ["/Users/taha/blog/app/controllers/application_controller", 2]
Ruby 2.6 adds more readable method Binding#source_location (Link is not available) to achieve similar result.
binding.source_location
=> ["/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.

Written byTaha Husain
Related blogs
- 01MJIT Support in Ruby 2.6March 5, 2019 · Sudeep Tarlekar
- 02Ruby 2.6 Range#cover? accepts Range object as argumentOctober 24, 2018 · Abhay Nikam
- 03Ruby 2.6 adds RubyVM::AST moduleOctober 2, 2018 · Amit Choudhary
- 04Ruby 2.6 adds Enumerable#filter as alias for #selectAugust 28, 2018 · Amit Choudhary