0
0

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.

Ruby 入門 [配列を繰り返し処理する]

Posted at

配列 [“カフェラテ”,”コーヒー”,”モカ”] 配列は複数のオブジェクトをまとめて使う道具

● .each do

配列.each do |変数|
 繰り返し実行する処理
end

● .map do

配列.map do |変数|
 変数処置
end

eachメソッドとmapメソッドの違い
mapメソッドはブロックを渡して各要素について処理を行う点が、eachメソッドと似ている。eachメソッドは各要素についてブロックで処理を行うことが目的となり、mapメソッドは各要素を変換した新しい配列を得ることが目的になることが多い。mapメソッドは使う機会が大変多いメソッド。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?