どんな時に使うの?
繰り返し処理をしたいとき。eachメソッドよりも短い記述で実現できる!
使い方
配列.map { | 変数 | 処理 }
例)文字列を全て大文字にする
strings = ["a", "b", "c"]
strings.map{ |s| s.upcase }
=> ["A", "B", "C"]
⭐️応用編
さらに簡潔な記述にするには?
→&(アンパサンド)を用いる!
例)strings = ["a", "b", "c"]
strings.map(&:upcase)
=> ["A", "B", "C"]