Actually, this is a general trick to understand any code: Find a concrete question -> get source code -> add breakpoints -> mess around -> observe the stacktrace…
Solid example
rubocop codebase is huge, what if I want to know how it works by observing one cop?
follow the steps bellow:
- clone the repo and cd into repo
- Run
bundle install
- add breakpoint in source code, e.g.: add
require 'pry'; binding.pry
to lib/rubocop/cop/lint/shadowed_exception.rb - find the executable of the gem, in this case
exe/rubocop
- Run
exe/rubocop --only Lint/ShadowedException tmp/shawdowed_exception.rb
and mess around with that breakpoint - Run
caller.grep /rubocop/
to see stacktrace
btw, go ahead to see spec/tests is also a good option.
Have fun reading source code
20220804 update
use exe/rubocop --cache false --only Lint/ShadowedException tmp/shawdowed_exception.rb
to avoid odd behaviors while debugging