Return an Enumerator from each* methods when no block is given

This commit is contained in:
David Cornu committed 2018-01-29 13:12:42 -05:00
1 parent 0b7b54119b
commit bc87711f9c
8 files changed
+54 -2

No files matched your search

+4 -2
View File
@@ -99,12 +99,14 @@ module Oga
end
# @see [Oga::XML::Node#each_ancestor]
def each_ancestor(&block)
def each_ancestor
return to_enum(:each_ancestor) unless block_given?
return unless element
yield element
element.each_ancestor(&block)
element.each_ancestor { |ancestor| yield ancestor }
end
private
+2
View File
@@ -180,6 +180,8 @@ module Oga
#
# @yieldparam [Oga::XML::Node]
def each_ancestor
return to_enum(:each_ancestor) unless block_given?
node = parent
while node.is_a?(XML::Element)
+2
View File
@@ -53,6 +53,8 @@ module Oga
#
# @yieldparam [Oga::XML::Node]
def each
return to_enum(:each) unless block_given?
@nodes.each { |node| yield node }
end
+2
View File
@@ -27,6 +27,8 @@ module Oga
#
# @yieldparam [Oga::XML::Node] The current node.
def each_node
return to_enum(:each_node) unless block_given?
visit = children.to_a.reverse
until visit.empty?