Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Node an Enumerable #24

Merged
merged 7 commits into from
May 18, 2016
Merged

Make Node an Enumerable #24

merged 7 commits into from
May 18, 2016

Conversation

gjtorikian
Copy link
Owner

Closes #23.

@dgraham, how's this work for you? walk has been renamed each so that all the Enumerable methods can function. I only added a test for select but can add more if you think there's something to explicitly test.

@dgraham
Copy link

dgraham commented May 17, 2016

The use case I was working with was iterating through a node's direct children without descending into the tree. So renaming each_child to each would fix that scenario.

Another possibility is to return an Enumerator from each_child if no block is given, similar to Array#each. That would allow this usage:

items = parent.each_child.select { |child| child.type == :list_item }

@gjtorikian
Copy link
Owner Author

Cool, I got you. I renamed each_child to each (well, it's an alias, because I didn't want to do a major version). Anything else you'd like to see?

each do |child|
child.walk(&block)
end
end
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be nice to return an Enumerator from walk, if no block is given, to match the behavior of each.

@gjtorikian gjtorikian merged commit 89f1a52 into master May 18, 2016
@gjtorikian gjtorikian deleted the enumerate branch May 18, 2016 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants