Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #2065
| From | "Kyle X." <haebooty@yahoo.com> |
|---|---|
| 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 | <bfa8a96c7e42c61220c2d0d954eca93c@ruby-forum.com> (permalink) |
| 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 | <bfa8a96c7e42c61220c2d0d954eca93c@ruby-forum.com> |
| 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 |
Show key headers only | View raw
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: #<TypeError: C:/Program Files
(x86)/Google/Google SketchUp 8/Plugins/examples/one.rb:61:in `[]': can't
convert REXML::Element into Integer>
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/.
Back to comp.lang.ruby | Previous | Next — Next in thread | Find similar | Unroll thread
Simple array.each do |x| question "Kyle X." <haebooty@yahoo.com> - 2011-03-31 17:26 -0500
Re: Simple array.each do |x| question Roger Braun <roger@rogerbraun.net> - 2011-03-31 17:35 -0500
Re: Simple array.each do |x| question "Kyle X." <haebooty@yahoo.com> - 2011-03-31 17:59 -0500
Re: Simple array.each do |x| question Gunther Diemant <g.diemant@gmx.net> - 2011-03-31 18:06 -0500
Re: Simple array.each do |x| question "Kyle X." <haebooty@yahoo.com> - 2011-03-31 18:30 -0500
Re: Simple array.each do |x| question "Kyle X." <haebooty@yahoo.com> - 2011-04-01 14:29 -0500
Re: Simple array.each do |x| question "Kyle X." <haebooty@yahoo.com> - 2011-04-01 15:31 -0500
Re: Simple array.each do |x| question "Kyle X." <haebooty@yahoo.com> - 2011-04-02 01:39 -0500
Re: Simple array.each do |x| question 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-02 13:32 -0500
Re: Simple array.each do |x| question 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-02 13:58 -0500
Re: Simple array.each do |x| question "Kyle X." <haebooty@yahoo.com> - 2011-04-04 13:55 -0500
Re: Simple array.each do |x| question "Kyle X." <haebooty@yahoo.com> - 2011-04-06 00:57 -0500
csiph-web