On Mon, 13 Mar 2006, Tomas Fischer wrote:

> Hi,
>
> I've got an array a= [1,2,3,4,5,6] and want to access each second
> element:
> b=[2,4,6]. How is this done in ruby?
>
> I know, that I can use a for-loob and modulo operator, but I think there
> is a "ruby way" of doing this.
>
> Thanks.
> tomas

Fixnum#step is one of the easiest ways to do this:

   harp:~ > cat a.rb
   a = [1, 2, 3, 4, 5, 6]
   1.step(a.size, 2){|i| p a[i]}


   harp:~ > ruby a.rb
   2
   4
   6

regards.

-a

-- 
share your knowledge.  it's a way to achieve immortality.
- h.h. the 14th dali lama