mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add ascend methods
This commit is contained in:
parent
8d366bf637
commit
c209fe7259
2 changed files with 16 additions and 5 deletions
|
@ -151,6 +151,15 @@ module Spectator
|
||||||
klass.cast(@context)
|
klass.cast(@context)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Yields this example and all parent groups.
|
||||||
|
def ascend
|
||||||
|
node = self
|
||||||
|
while node
|
||||||
|
yield node
|
||||||
|
node = node.group?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Constructs the full name or description of the example.
|
# Constructs the full name or description of the example.
|
||||||
# This prepends names of groups this example is part of.
|
# This prepends names of groups this example is part of.
|
||||||
def to_s(io)
|
def to_s(io)
|
||||||
|
|
|
@ -72,11 +72,13 @@ module Spectator
|
||||||
|
|
||||||
delegate size, unsafe_fetch, to: @nodes
|
delegate size, unsafe_fetch, to: @nodes
|
||||||
|
|
||||||
# Creates a child that is attched to the group.
|
# Yields this group and all parent groups.
|
||||||
# Yields zero or more times to create the child.
|
def ascend
|
||||||
# The group the child should be attached to is provided as a block argument.
|
group = self
|
||||||
def create_child
|
while group
|
||||||
yield self
|
yield group
|
||||||
|
group = group.group?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Removes the specified *node* from the group.
|
# Removes the specified *node* from the group.
|
||||||
|
|
Loading…
Reference in a new issue