Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: Add architecture note for DefinitionBuilder and AncestorBuilder #1556

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions docs/architecture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Architecture of RBS

## Definition and DefinitionBuilder

`DefinitionBuilder` is a class to build `Definition` that has a list of instance methods and a list of class methods, from the ancestors of the target class or module.

For example, a built-in class `String` has the following ancestors:

* `String` (itself)
* `Comparable`
* `Object`
* `Kernel`
* `BasicObject`

And then, `DefinitionBuilder` gathers instance methods from these ancestors, gathers class methods from them, and builds them up to a `Definition`.

On the building, `DefinitionBuilder` internally uses `DefinitionBuilder::AncestorBuilder` to calculate the list of ancestors.

* `AncestorBuilder#one_singleton_ancestors` calculates nearest ancestors for the singleton methods
* `AncestorBuilder#one_singleton_ancestors` calculates nearest ancestors for the instance methods
* `AncestorBuilder#singleton_ancestors` returns all ancestors (class and modules) for the singleton methods
* `#singleton_ancestors` internally uses `#one_singleton_ancestors` and calls it recursively
* `AncestorBuilder#instance_ancestors` returns all ancestors for the instance methods
* `#instance_ancestors` internally uses `#one_instance_ancestors` and calls it recursively