Ruby: add Module.getNamespaceOrTopLevel

This commit is contained in:
Asger F
2022-10-17 19:54:27 +02:00
parent 1f644a9c1d
commit c8f7519cee

View File

@@ -241,6 +241,14 @@ class ModuleBase extends BodyStmt, Scope, TModuleBase {
* Does not include the `self` variable from any of the methods in the module.
*/
SelfVariable getModuleSelfVariable() { result.getDeclaringScope() = this }
/** Gets the nearest enclosing `Namespace` or `Toplevel`, possibly this module itself. */
Namespace getNamespaceOrToplevel() {
result = this
or
not this instanceof Namespace and
result = this.getEnclosingModule().getNamespaceOrToplevel()
}
}
/**