Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #2126

Re: Simple array.each do |x| question

From "Kyle X." <haebooty@yahoo.com>
Newsgroups comp.lang.ruby
Subject Re: Simple array.each do |x| question
Date Fri, 1 Apr 2011 15:31:26 -0500
Organization Service de news de lacave.net
Lines 51
Message-ID <c62e989475c0c5d217bb736ba39e597f@ruby-forum.com> (permalink)
References <bfa8a96c7e42c61220c2d0d954eca93c@ruby-forum.com> <AANLkTimQUjNP75z30+-zYYXD15BZNou6PvEDcic_eFn2@mail.gmail.com> <9d19e7d38f2f3b6ab99b3150717a307c@ruby-forum.com> <AANLkTinUfc7WfoXosbPVFG5P7YBgCF8RVAzhVUN9FAAm@mail.gmail.com> <6f6bb08b25ceb72409f83615448a82b6@ruby-forum.com> <20110401193110.GA86296@guilt.hydra>
NNTP-Posting-Host bristol.highgroove.com
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 7bit
X-Trace talisker.lacave.net 1301689906 64418 65.111.164.187 (1 Apr 2011 20:31:46 GMT)
X-Complaints-To abuse@lacave.net
NNTP-Posting-Date Fri, 1 Apr 2011 20:31:46 +0000 (UTC)
In-Reply-To <20110401193110.GA86296@guilt.hydra>
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 380768
X-Ml-Name ruby-talk
X-Rubymirror Yes
X-Ruby-Talk <c62e989475c0c5d217bb736ba39e597f@ruby-forum.com>
Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!feed.ac-versailles.fr!talisker.lacave.net!lacave.net!not-for-mail
Xref x330-a1.tempe.blueboxinc.net comp.lang.ruby:2126

Show key headers only | View raw


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 | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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