문제

How can i specify which index to start from when using each_with_index on a collection in ruby 1.8.7?

collection.each_with_index do |element, index = 1|
  #do smth
end

Using it like this gives the following error:

syntax error, unexpected '=', expecting '|'
collection.each_with_index do |element, i = 1|
도움이 되었습니까?

해결책

try this:

collection[4..-1].each_with_index do |element, index|
  #do smth
end

this example will start from fifth element.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top