LoginSignup
3
0

More than 3 years have passed since last update.

each_with_objectでwith_indexしたい

Last updated at Posted at 2020-02-18

いけた

が、使える引数の順番が複雑な感じ。カッコも必要。
カッコ内の引数:each_with_objectの第1引数、第2引数
カッコ外の引数:with_indexで追加された引数
ということのようだ。

(1..3).each_with_object([]).with_index do |(data, arr), index|
 data # (1..3)の配列内のデータ
 arr # each_with_objectの引数に渡した配列
 index # インデックス
end

参考

3
0
0

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
3
0