[Ruby] When reading the source code

less than 1 minute read

When you enter an existing project, you will need to check what methods each Class has.

At that time, I would like to describe below how I am confirming.

[environment]
Ruby
Rails
Solidus

This time, I would like to explain using Rails’ Solidus gem.
download.png

$rails c
Enter the console with.

Therefore, as described above, the object is assigned to an arbitrary character.
(Spree :: Taxon is an object)

$a.methods
Execute. By executing it, the method that the object has is displayed.

download (1).png

$a.methods.grep /product/
Then, only the method related to product can be obtained.
By using grep as described above, you can narrow down the search results and search, so I think that there are many opportunities to use it.

download (2).png

$a.method(:before_remove_for_products=).source_location
As mentioned above, by setting method (method name) .source_location,
You can also find out in which file the method is located.