Top > Ruby [2.2.2] > each_with_index


Enumerable# each_with_index

test = ["acha","porute","piipo"]

test.each_with_index do |value, index|
  print index, "-", value, "\n"
end
                        # 0-acha
                        # 1-porute
                        # 2-piipo

重宝するやつです。
for eachと使い分けましょう



Copyright © 2015 AchaPorutePiipo All Rights Reserved.