Declaring an integer Range with step != 1 in Ruby

后端 未结 3 1660
感情败类
感情败类 2020-12-17 15:09

UPDATE 2: For posterity, this is how I\'ve settled on doing it (thanks to Jorg\'s input):

100.step(2, -2) do |x|
    # my code
end
         


        
3条回答
  •  不知归路
    2020-12-17 15:29

    This question answers yours: about ruby range?

    (2..100).step(2) do |x|
        # your code
    end
    

提交回复
热议问题