Sorbet supports method override checking. These checks are implemented as
overridablemeans children can override this method
overridemeans this method overrides a method on its parent (or ancestor), which may or may not be an abstract or interface method
abstractmeans this method is abstract (has no implementation) and must be implemented by being overridden in all concrete subclasses.
These annotations can be chained, for example
.override.overridable lets a
grandchild class override a concrete implementation of its parent.
Use this table to track when annotations can be used, although the error messages are the canonical source of truth. ✅ means “this pairing is allowed” while ❌ means "this is an error".
standard(for the child or parent) means “has a
sig, but has none of the special modifiers.”
|↓Parent \ Child →||no sig|
Some other things are checked that don’t fit into the above table:
- It is an error to mark a method
overrideif the method doesn’t actually override anything.
- If the implementation methods are inherited–from either a class or mixin–the
methods don’t need the
Note that the absence of
overridable does not mean that
a method is never overridden. To declare that a method can never be overridden,
look into final methods.
Learn how to prohibit overriding entirely, both at the method level and the class level.
Marking methods as
abstractand requiring child classes to implement them is a powerful tool for code organization and correctness. Learn more about Sorbet’s support for abstract classes and interfaces.