Working As Intended

Finding the source code for a Ruby method.

February 11th 2015

Today I discovered Ruby’s Method#source_location. I was getting strange results in a test case and wanted to see what was going on inside of xhr.

I added a breakpoint to my test.

byebug xhr :get, :show, id:

And then in the console that came up from running the test I was able to pull up the file and line number for this method.

(byebug) self.method(:xhr).source_location [“/[…]/gems/actionpack-4.2.0/lib/action_controller/test_case.rb”, 538]

blog comments powered by Disqus

Feed Feed