Don't yield indexes in Document#each_node.

These indexes won't be used so there's no point in yielding them.
This commit is contained in:
Yorick Peterse 2014-08-04 09:08:39 +02:00
parent 4dc85df4e7
commit ef1ad5406a
2 changed files with 2 additions and 14 deletions

View File

@ -54,7 +54,7 @@ module Oga
# block. # block.
# #
# @example # @example
# document.each_node do |node, index| # document.each_node do |node|
# p node.class # p node.class
# end # end
# #
@ -63,18 +63,14 @@ module Oga
# http://en.wikipedia.org/wiki/Breadth-first_search for more information. # http://en.wikipedia.org/wiki/Breadth-first_search for more information.
# #
# @yieldparam [Oga::XML::Node] The current node. # @yieldparam [Oga::XML::Node] The current node.
# @yieldparam [Fixnum] The current node's index.
# #
def each_node def each_node
visit = children.to_a.dup # copy it since we're modifying the array visit = children.to_a.dup # copy it since we're modifying the array
index = 0
until visit.empty? until visit.empty?
current = visit.shift current = visit.shift
yield current, index yield current
index += 1
visit = current.children.to_a + visit visit = current.children.to_a + visit
end end

View File

@ -53,14 +53,6 @@ describe Oga::XML::Document do
names.should == %w{books book1 title1 Foo book2 title2 Bar} names.should == %w{books book1 title1 Foo book2 title2 Bar}
end end
example 'yield the document indexes' do
indexes = []
@document.each_node { |_, index| indexes << index }
indexes.should == [0, 1, 2, 3, 4, 5, 6]
end
end end
context '#to_xml' do context '#to_xml' do