1
1

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 3 years have passed since last update.

zipメソッドを使って複数の配列を同時に取り出す

Last updated at Posted at 2021-02-08

##複数のタグを同時に表示させたかった
タグ付け機能を複数実装し、同じページに表示させようとした際に便利なメソッドを見つけたので備忘録として残しておく。

##zipメソッドの使い方
zipメソッドを使うことで、複数の配列から同時に取り出すことができる。

tag1 = ['test1', 'test2', 'test3']
tag2 = ['テスト1', 'テスト2', 'テスト3']

tag1.zip(tag2) do |tag1, tag2|
  puts tag1
  puts tag2
end

上記のように記述すると以下の実行結果となる。

test1
テスト1
test2
テスト2
test3
テスト3
1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?