tags:

views:

62

answers:

3

Perl allows you to use the '..' operator to return a slice from an array. So if I wanted cells 4 through 8 from an array, I could this:

sample_array[4..8]

And if I assigned that to a new array, it would only have those 5 cells. Is there an operator like this for Ruby?

Thanks.

A: 

Hmm, wouldn't trying it yourself be faster than asking?

Yes, there's such operator. Working exactly like you described.

Nikita Rybak
+1  A: 

You answered your own question. The Array#[] method can take a range, and return slices of that array.

AboutRuby
+1  A: 

You seem to have answered your own question, but fwiw, here is the Array#[] documentation which shows some more possibilities.

Douglas