Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #2126
| From | "Kyle X." <haebooty@yahoo.com> |
|---|---|
| Newsgroups | comp.lang.ruby |
| Subject | Re: Simple array.each do |x| question |
| Date | 2011-04-01 15:31 -0500 |
| Organization | Service de news de lacave.net |
| Message-ID | <c62e989475c0c5d217bb736ba39e597f@ruby-forum.com> (permalink) |
| References | (1 earlier) <AANLkTimQUjNP75z30+-zYYXD15BZNou6PvEDcic_eFn2@mail.gmail.com> <9d19e7d38f2f3b6ab99b3150717a307c@ruby-forum.com> <AANLkTinUfc7WfoXosbPVFG5P7YBgCF8RVAzhVUN9FAAm@mail.gmail.com> <6f6bb08b25ceb72409f83615448a82b6@ruby-forum.com> <20110401193110.GA86296@guilt.hydra> |
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/.
Back to comp.lang.ruby | Previous | Next — Previous in thread | 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