MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / selfIsTheClass

Function selfIsTheClass

src/resolution/ruby-parameter-flow.ts:507–527  ·  view source on GitHub ↗
(method: FlowMethod, scope: FlowMethod)

Source from the content-addressed store, hash-verified

505
506 /** Whether `method`, a `def` directly in its class, can only ever run with that class's `self`. */
507 const selfIsTheClass = (method: FlowMethod, scope: FlowMethod): boolean => {
508 let answer = selfMemo.get(method.id);
509 if (answer !== undefined) return answer;
510 const lines = linesOf(method.filePath);
511 answer = true;
512 for (let i = method.startLine - 1; answer && i < method.endLine && i < lines.length; i++) {
513 if (OTHER_SELF.test(lines.at(i)!)) answer = false;
514 }
515 // A `def` inside a block of the class body (`included do`, `Struct.new
516 // do`) belongs to whatever the block runs on.
517 let indent = (lines.at(method.startLine - 1) ?? '').search(/\S/);
518 for (let i = method.startLine - 2; answer && i >= scope.startLine; i--) {
519 const line = lines.at(i)!;
520 const at = line.search(/\S/);
521 if (at < 0 || at >= indent || line[at] === '#') continue;
522 indent = at;
523 if (/(?:\bdo(?:\s*\|[^|]*\|)?|\{(?:\s*\|[^|]*\|)?)\s*(?:#.*)?$/.test(line)) answer = false;
524 }
525 selfMemo.set(method.id, answer);
526 return answer;
527 };
528
529 /** The value of `self` at a site: only inside a method of a class says which. */
530 const selfValue = (site: FlowSite): FlowValue | Abstention => {

Callers 1

selfValueFunction · 0.85

Calls 5

searchMethod · 0.80
linesOfFunction · 0.70
getMethod · 0.65
atMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected