2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Ruby:二次元配列を取り出しメモ

Posted at

二次元配列を使う時にはeachを二重にして取り出していたが、
ブロック引数に複数指定すれば中の配列の要素がそのまま取り出せそう

これまでの書き方

qiita.rb
array = [[1,2,3], [4,5,6], [7,8,9]]
array.each do |ary|
  ary.each do |fed|
    puts fed
  end
end

###短くしたい
とにかく短くしたいと調べてて見つけた書き方

qiita.rb
array = [[1,2,3], [4,5,6], [7,8,9]]
array.each do |fed1, fed2, fed3|
  puts fed1, fed2, fed3
end

これで少し短くなりました。

2
3
1

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?