---
title: "Ruby 2.6 adds Binding#source_location"
description:
  "Binding#source_location is added in Ruby 2.6 which makes fetching filename
  and line number more readable"
canonical_url: "https://www.bigbinary.com/blog/ruby-2-6-adds-binding-source-location"
markdown_url: "https://www.bigbinary.com/blog/ruby-2-6-adds-binding-source-location.md"
---

# Ruby 2.6 adds Binding#source_location

Binding#source_location is added in Ruby 2.6 which makes fetching filename and
line number more readable

- Author: Taha Husain
- Published: July 24, 2018
- Categories: Ruby 2.6, Ruby

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) .

```ruby
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.

```ruby
binding.source_location
=> ["/Users/taha/blog/app/controllers/application_controller", 2]
```

Here is relevant [commit](https://github.com/ruby/ruby/commit/571e48) and
[discussion](https://bugs.ruby-lang.org/issues/14230) for this change.

The Chinese version of this blog is available
[here](http://madao.me/yi-ruby-2-6-binding-dui-xiang-zeng-jia-source_location-fang-fa/).

## Links

- [Human page](https://www.bigbinary.com/blog/ruby-2-6-adds-binding-source-location)
