use*_*719 0 ruby
给定这个数组: a = ["a", "b", "c"]
a = ["a", "b", "c"]
如果我跑,a.cycle { |x| puts x }我得到print, a, b, c, a, b, c,.. forever.
a.cycle { |x| puts x }
print, a, b, c, a, b, c,.. forever.
有没有办法设置起点,以便它以"b"或第二个索引开头,如下所示:print, b, c, a, b, c, a,.. forever.?
print, b, c, a, b, c, a,.. forever.
roh*_*t89 5
使用 Array#rotate
Array#rotate
a.rotate.cycle {|x| puts x}
传递参数以rotate转移到您想要的任何索引.
rotate
归档时间:
11 年,1 月 前
查看次数:
60 次
最近记录: