Skip to content

Commit fc90479

Browse files
committed
Add a Node.root helper method
1 parent 672b9cf commit fc90479

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

lib/Terminal/Widgets/Volatile/DirTree.rakumod

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ role Node {
1313
my $short-name = self.^name.subst('Terminal::Widgets::Volatile::', '');
1414
$short-name ~ ':' ~ $!path.path
1515
}
16+
17+
#| Find root node via parent chain, runtime is O(depth)
18+
method root(::?CLASS:D:) {
19+
my $root = self;
20+
$root .= parent while $root.parent;
21+
$root
22+
}
1623
}
1724

1825
class Dev does Node {

0 commit comments

Comments
 (0)