Ruby and Rails via rails console or irb is these days pretty inspectable.
Say you want to understand what does `belongs_to` do?
Just open `rails console` and you can do:
User.method(:belongs_to).source_location
And opening the file that is printed at the specified line, you can discover the following code:
def belongs_to(name, scope = nil, **options)
reflection = Builder::BelongsTo.build(self, name, scope, options)
Reflection.add_reflection self, name, reflection
end
And moreso that method has a very good comment before the declaration, documenting everything it does
You can also try `show_source` command in Rails console if you have the debug gem installed:
show_source User.find
And this will directly show the source code of the `find` method.
I do agree that for methods defined with meta-programming it will be harder to find the methods.
But again here rails console comes with help:
For example if you do:
User.method(:find_by_name)
=>
#<Method: User(id: integer, nickname: string, name: string, created_at: datetime, updated_at: datetime).find_by_name(_name) <edited by me>/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.8.4/lib/active_record/dynamic_matchers.rb:65>
Of course, this is mode complex meta-programming code, but you can still go to it, read it, and see what it does.
In case of relationships between entities in the code, you can try Sorbet. It is pretty good these days.