Return an Enumerator from each* methods when no block is given
This commit is contained in:
1 parent
0b7b54119b
commit
bc87711f9c
8 files changed
+54
-2
No files matched your search
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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?
|
||||
|
||||
Reference in new issue
Block a user