设置循环的起点()

use*_*719 0 ruby

给定这个数组: a = ["a", "b", "c"]

如果我跑,a.cycle { |x| puts x }我得到print, a, b, c, a, b, c,.. forever.

有没有办法设置起点,以便它以"b"或第二个索引开头,如下所示:print, b, c, a, b, c, a,.. forever.

roh*_*t89 5

使用 Array#rotate

a.rotate.cycle {|x| puts x}

传递参数以rotate转移到您想要的任何索引.