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 | 2011-03-31 17:26 -0500 |
| Organization | Service de news de lacave.net |
| Message-ID | <bfa8a96c7e42c61220c2d0d954eca93c@ruby-forum.com> (permalink) |
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