Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c8f7519

Browse files
committed
Ruby: add Module.getNamespaceOrTopLevel
1 parent 1f644a9 commit c8f7519

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

ruby/ql/lib/codeql/ruby/ast/Module.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,14 @@ class ModuleBase extends BodyStmt, Scope, TModuleBase {
241241
* Does not include the `self` variable from any of the methods in the module.
242242
*/
243243
SelfVariable getModuleSelfVariable() { result.getDeclaringScope() = this }
244+
245+
/** Gets the nearest enclosing `Namespace` or `Toplevel`, possibly this module itself. */
246+
Namespace getNamespaceOrToplevel() {
247+
result = this
248+
or
249+
not this instanceof Namespace and
250+
result = this.getEnclosingModule().getNamespaceOrToplevel()
251+
}
244252
}
245253

246254
/**

0 commit comments

Comments
 (0)