Chad Perrin wrote in post #990462:
> On Sat, Apr 02, 2011 at 04:29:13AM +0900, Kyle X. wrote:
>> {|element| element.text}
>>   elements << x
>>   n=n+1
>> end
>
> I seem to have misplaced the thread so far, so please forgive me if I'm
> asking something redundant.
>
> What is the relationship between reference1 and reference2?
>

I am sorry for not including this.  reference1 and reference2 are two 
arrays of the same length that contain strings.

If you were to do -
p reference1
#This would be the output->
#["i1671", "i1793", "i1919", "i2045"]


> If they are the same, you should be able to do a very simple swap of
> terms between your while loop version and an each iterator:
>
>     elements = []
>     reference2.each do |ref|
>       x = REXML::XPath.match(
>         doc,
>         "//*[@id='#{ref}']/Coordinates/IfcLengthMeasure"
>       ).map {|element| element.text }
>
>       elements << x
>     end
>
> (adjusted to reduce horizontal sprawl)
>
> If reference1 and reference2 are not the same length, however, this
> approach will not work.  The lack of descriptive meaning in your
> variable
> names is a bit daunting when trying to figure out the intentions behind
> your code.
>
> I'll come back to the second while loop later, if someone else has not
> already gotten to it by then.

Thank you for the response I will try it out.

-- 
Posted via http://www.ruby-forum.com/.