CommonThread

Tip: Ruby On Rails to And from

Posted by anthony crumley, Tue Dec 04 17:33:00 UTC 2007

In Rails 2.0 arrays will have to and from methods that work like the ones on strings. The to(position) method will return elements from the beginning of the array up to and including the position passed in. The from(position) method will return elements from the position passed in to the end of the array.

[1, 2, 3].to(1) => [1, 2]
[a, b, c].from(1) => [b, c]

Filed Under: | Tags:

Comments

Have your say

A name is required. You may use HTML in your comments.




Categories