Chris Richards
2006-May-12 15:19 UTC
[Rails] each_with_index. Can you start at a desired index position?
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 -- Posted via http://www.ruby-forum.com/.
Brian Buckley
2006-May-12 17:40 UTC
[Rails] each_with_index. Can you start at a desired index position?
Here''s one way. array[20..-1].each_with_index do |value,index| ... end Brian Buckley On 5/12/06, Chris Richards <evilgeenius@gmail.com> wrote:> > 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 > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Brian K. Buckley briankbuckley@gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060512/06537ba1/attachment.html