ruby 2.6からはRubyで添え字付きでループを回し、かつ0以外の数値で開始したいときzip(1..)
出来るのでチル📻
fruits = ['apple', 'orange', 'melon']
fruits.zip(1..) {|fruit, i| puts "#{i}: #{fruit}" }
# 1: apple
# 2: orange
# 3: melon
each_with_indexには引数を渡せない、わけではないを読んで韻を踏みたくなったので書きました。
Go to list of users who liked
More than 5 years have passed since last update.
ruby 2.6からはRubyで添え字付きでループを回し、かつ0以外の数値で開始したいときzip(1..)
出来るのでチル📻
fruits = ['apple', 'orange', 'melon']
fruits.zip(1..) {|fruit, i| puts "#{i}: #{fruit}" }
# 1: apple
# 2: orange
# 3: melon
each_with_indexには引数を渡せない、わけではないを読んで韻を踏みたくなったので書きました。
Register as a new user and use Qiita more conveniently
Go to list of users who liked