Find where the method lies : source_location
While checking out some Rails magic happening or even while rollercoasting into a very large codebase, it would be really super duper helpful if there could be something that would help to find where the method was defined. (Ofcourse, there are these cool text editors that help to find this but they generally don’t reach inside gems)
source_location is the method that comes to our rescue!
We have a take the object which we are curious about and then chain it to
method method with the method we are searching for and chain this to
Woww this looks so confusing but be rest assured it is not. Let’s go.
So this returns an Array of results :
The first element shows the path of the file where the method is stored
The second element shows the line number where the method is define
This can be nifty tool to to debug a lot of stuff, learn new things about implementation of code and really really helpful to have a in the Metaprogrammed methods.
To learn more about more nifty such methods you can visit Ruby official methods here here.
Thanks to Prathamesh Sonpatki for bringing this my knowledge.