ReXML elements#each vs 1.9.3 documentation for same

includes the following example:

doc = Document.new ‘sean
doc.root.each {|e|p e} #-> Yields b, c, d, b, c, d elements
doc.root.each(‘b’) {|e|p e} #-> Yields b, b elements

However when I run it I get the results below.

Am I doing something wrong? If not, is the documentation or the code
correct? Should I be reporting this somewhere?

(My underlying goal is to find an iterator that yields one element at a
time from an XPath search, rather than doing the whole search to return
a complete array of elements.)

Running the example:

Sleek:iTunes_Library_Update Wes$ rvm 1.9.3

Sleek:iTunes_Library_Update Wes$ ruby -v
ruby 1.9.3p327 (2012-11-10) [x86_64-darwin12.2.0]

Sleek:iTunes_Library_Update Wes$ ruby rexml_question.rb



“sean”



/Users/Wes/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/rexml/parent.rb:40:in
each': wrong number of arguments (1 for 0) (ArgumentError) from rexml_question.rb:10:in

Sleek:iTunes_Library_Update Wes$ cat < rexml_question.rb
#! /usr/bin/env ruby
require “rexml/document”
include REXML

STDOUT.sync = true

doc = Document.new ‘sean
doc.root.each {|e|p e} #-> Yields b, c, d, b, c, d elements
doc.root.each(‘b’) {|e|p e} #-> Yields b, b elements
doc.root.each(‘child::node()’) {|e|p e}
#-> Yields , , , , ,
XPath.each(doc.root, ‘child::node()’, &block)
#-> Yields , , , sean, , ,

Sleek:iTunes_Library_Update Wes$

Hi,

In [email protected]
“rexml.elements.each vs 1.9.3 documentation for same” on Thu, 3 Jan
2013 14:26:56 +0900,
Wesley R. [email protected] wrote:

Am I doing something wrong? If not, is the documentation or the code
correct? Should I be reporting this somewhere?

Thanks for your report.

The sample code in the documentation is wrong.
It should be

doc.root.elements.each

instead of

doc.root.each

.

I’ve fixed it in trunk.

Thanks,