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) 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)

View file

@ -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.