From: "Kyle X." Newsgroups: comp.lang.ruby Subject: Simple array.each do |x| question Date: Thu, 31 Mar 2011 17:26:14 -0500 Organization: Service de news de lacave.net Lines: 37 Message-ID: NNTP-Posting-Host: bristol.highgroove.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: talisker.lacave.net 1301610427 20431 65.111.164.187 (31 Mar 2011 22:27:07 GMT) X-Complaints-To: abuse@lacave.net NNTP-Posting-Date: Thu, 31 Mar 2011 22:27:07 +0000 (UTC) X-Received-From: This message has been automatically forwarded from the ruby-talk mailing list by a gateway at comp.lang.ruby. If it is SPAM, it did not originate at comp.lang.ruby. Please report the original sender, and not us. Thanks! For more details about this gateway, please visit: http://blog.grayproductions.net/categories/the_gateway X-Mail-Count: 380710 X-Ml-Name: ruby-talk X-Rubymirror: Yes X-Ruby-Talk: Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.stben.net!talisker.lacave.net!lacave.net!not-for-mail Xref: x330-a1.tempe.blueboxinc.net comp.lang.ruby:2065 Hello, I am new to ruby and cannot understand why this code is not working: direction = doc.elements.each("doc:iso_10303_28/uos/IfcCartesianPoint") { |element| puts element.attributes["id"] } # this produces [i1586,i1667,i1915,i2041,i2160] result = [] direction.each do |z| n = direction[z].attribute["id"] result << n end This gives me the following error: Error: # However when I use the following code, which to me seems to do exactly the same thing in a less sophisticated manner, it works without issue: direction = doc.elements.each("doc:iso_10303_28/uos/IfcCartesianPoint") { |element| puts element.attributes["id"] } n=0 result = [] while n != direction.length z = direction[n].attributes["id"] result << z n=n+1 end #output - > ["i1586", "i1667", "i1915", "i2041", "i2160"] Any ideas? Addition info - Ruby 1.8.6. -- Posted via http://www.ruby-forum.com/.