Ruby each_with_index offset

前端 未结 10 1165
长发绾君心
长发绾君心 2020-12-12 23:32

Can I define the offset of the index in the each_with_index loop iterator? My straight forward attempt failed:

some_array.each_with_index{|item, index = 1| s         


        
10条回答
  •  孤街浪徒
    2020-12-12 23:55

    I ran into it.

    My solution not necessary is the best, but it just worked for me.

    In the view iteration:

    just add: index + 1

    That's all for me, as I don't use any reference to those index numbers but just for show in a list.

提交回复
热议问题