Skip to content

Commit

Permalink
Merge branch '1765-enumerator'
Browse files Browse the repository at this point in the history
  • Loading branch information
flavorjones committed Jun 16, 2018
2 parents 96a4574 + 00bafb7 commit 06ac6ba
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/nokogiri/xml/node_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ def remove_attr name
###
# Iterate over each node, yielding to +block+
def each(&block)
return to_enum unless block_given?

0.upto(length - 1) do |x|
yield self[x]
end
Expand Down
8 changes: 8 additions & 0 deletions test/xml/test_node_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,14 @@ def test_include_on_empty_node_set
assert ! empty_set.include?(employee)
end

def test_each
employees = @xml.search("//employee")
enum = employees.each
assert_instance_of Enumerator, enum
assert_equal enum.next, employees[0]
assert_equal enum.next, employees[1]
end

def test_children
employees = @xml.search("//employee")
count = 0
Expand Down

0 comments on commit 06ac6ba

Please sign in to comment.