From ef1ad5406a6d9edfd4510f177b4528518c384778 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Mon, 4 Aug 2014 09:08:39 +0200 Subject: [PATCH] Don't yield indexes in Document#each_node. These indexes won't be used so there's no point in yielding them. --- lib/oga/xml/document.rb | 8 ++------ spec/oga/xml/document_spec.rb | 8 -------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/lib/oga/xml/document.rb b/lib/oga/xml/document.rb index 3abbe11..d3fd57a 100644 --- a/lib/oga/xml/document.rb +++ b/lib/oga/xml/document.rb @@ -54,7 +54,7 @@ module Oga # block. # # @example - # document.each_node do |node, index| + # document.each_node do |node| # p node.class # end # @@ -63,18 +63,14 @@ module Oga # http://en.wikipedia.org/wiki/Breadth-first_search for more information. # # @yieldparam [Oga::XML::Node] The current node. - # @yieldparam [Fixnum] The current node's index. # def each_node visit = children.to_a.dup # copy it since we're modifying the array - index = 0 until visit.empty? current = visit.shift - yield current, index - - index += 1 + yield current visit = current.children.to_a + visit end diff --git a/spec/oga/xml/document_spec.rb b/spec/oga/xml/document_spec.rb index 01d43bb..3130300 100644 --- a/spec/oga/xml/document_spec.rb +++ b/spec/oga/xml/document_spec.rb @@ -53,14 +53,6 @@ describe Oga::XML::Document do names.should == %w{books book1 title1 Foo book2 title2 Bar} 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 context '#to_xml' do