4
1

More than 5 years have passed since last update.

rubyは1..でzip出来るのでチル

Last updated at Posted at 2018-08-09

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には引数を渡せない、わけではないを読んで韻を踏みたくなったので書きました。

4
1
5

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1