Add ascend methods

This commit is contained in:
Michael Miller 2021-08-17 22:10:01 -06:00
parent 8d366bf637
commit c209fe7259
No known key found for this signature in database
GPG key ID: F9A0C5C65B162436
2 changed files with 16 additions and 5 deletions

View file

@ -151,6 +151,15 @@ module Spectator
klass.cast(@context)
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.
# This prepends names of groups this example is part of.
def to_s(io)

View file

@ -72,11 +72,13 @@ module Spectator
delegate size, unsafe_fetch, to: @nodes
# Creates a child that is attched to the group.
# Yields zero or more times to create the child.
# The group the child should be attached to is provided as a block argument.
def create_child
yield self
# Yields this group and all parent groups.
def ascend
group = self
while group
yield group
group = group.group?
end
end
# Removes the specified *node* from the group.