Skip to content

Commit 75517e0

Browse files
morishjsflavorjones
authored andcommitted
'#each' returns enumerator when no block given
1 parent 96a4574 commit 75517e0

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

lib/nokogiri/xml/node_set.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ def remove_attr name
198198
###
199199
# Iterate over each node, yielding to +block+
200200
def each(&block)
201+
return to_enum unless block_given?
202+
201203
0.upto(length - 1) do |x|
202204
yield self[x]
203205
end

test/xml/test_node_set.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,11 @@ def test_include_on_empty_node_set
672672
assert ! empty_set.include?(employee)
673673
end
674674

675+
def test_each
676+
employees = @xml.search("//employee")
677+
assert_instance_of Enumerator, employees.each
678+
end
679+
675680
def test_children
676681
employees = @xml.search("//employee")
677682
count = 0

0 commit comments

Comments
 (0)