Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想@a从:循环0。20, 1, 2, 0, 1, 2
@a
0
2
0, 1, 2, 0, 1, 2
def set_a if @a == 2 @a = 0 else @a = @a + 1 end end
也许有更好的方法?
(0..2).cycle(3) { |x| puts x } #=> 0,1,2,0,1,2,0,1,2 item = [0, 1, 2].cycle.each item.next #=> 0 item.next #=> 1 item.next #=> 2 item.next #=> 0 ...