Finding The Source of Ruby Methods
Last updated
Was this helpful?
Last updated
Was this helpful?
Ruby's class includes a feature that can help you quickly find the location of source code files where a particular method is defined. The method is aptly named .
When debugging a project that is using the gem, you can take a source dive by first finding the relevant source files. For instance, if you want to look into the word creation functionality, you might go through an exploratory process like the following:
You can now take a closer look at the implementation of the build
method.
The main caveat to this process is that it can only find source locations for methods defined in ruby land. Calling source_location
on any method defined in C code will result in nil
.