Ruby 1.8.7 each_with_index index offset
-
11-06-2021 - |
문제
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.
제휴하지 않습니다 StackOverflow