On Tue, Dec 03, 2002 at 11:57:48PM +0900, David A. Black wrote:
> 
> 
> On Tue, 3 Dec 2002, Mauricio [iso-8859-1] FernŠŌdez wrote:
> 
> > On Tue, Dec 03, 2002 at 10:58:15PM +0900, Roman Rytov wrote:
> > >
> > > Anotehr question is about COLLECT;
> > >
> > > myarray.collect {|x| x + ", "}
> > >
> > > I wanna execute only over specific emelents (let's say only odd ones or
> > > all but last).
> >
> > myarray.select{ |x| x % 2 == 1 }.collect{ |x| x + ", " }  #.join here ?
> 
> That's going to work only on numerical elements... which the
> collect clause then won't work on.  I think Roman meant odd-numbered
> indices (?).  (Which doesn't explain why I used even-numbered
> indices in my example -- oh well :-)

I took it too literally :-) "only odd elements". And you're right about #+
not working then...

As there's no select_with_index (nor select_index), this is the shortest
thing I can think of right now:

 v = []
 myarray.each_with_index { |x,i| v << x if i % 2 == 1 }
 v.collect{ |x| "#{x}, "} 

-- 
 _           _                             
| |__   __ _| |_ ___ _ __ ___   __ _ _ __  
| '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ 
| |_) | (_| | |_\__ \ | | | | | (_| | | | |
|_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_|
	Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

*** PUBLIC flooding detected from erikyyy
<lewnie> THAT's an erik, pholx.... ;)
	-- Seen on #LinuxGER