Forum: Ruby on Rails each_with_index. Can you start at a desired index position?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Cd8c9864d88bcafc164d8fdb820cc451?d=identicon&s=25 Chris Richards (chris)
on 2006-05-12 17:19
When using array.each_with_index how do you start at a desired index
position?

I can do it like this, but its not very clean and doesnt seem efficient
:

desired_index_start = 20
array.each_with_index do |value,index|
  next if index<desired_index_start
end

Thanks
Chris
9a46755c817121b0571a563e5ab02090?d=identicon&s=25 Brian Buckley (brian)
on 2006-05-12 19:41
(Received via mailing list)
Here's one way.

array[20..-1].each_with_index do |value,index|
  ...
end

Brian Buckley
This topic is locked and can not be replied to.