map
配列の入った変数.map {|変数名| 処理内容 }
food = ["fish", "beef", "banana","potato"]
food.map {|a| a.length}
# 元の配列の変更していない
# 戻り値は [4, 4, 6, 6]
map!(破壊的メソッド)
配列の入った変数.map! {|変数名| 処理内容 }
food = ["fish", "beef", "banana","potato"]
food.map! {|a| a.length}
# 元の配列の変更している
# 戻り値は [4, 4, 6, 6]
each(mapとの違い)
food = ["fish", "beef", "banana","potato"]
food.each {|a| a.length}
# 戻り値がもとの配列を返す
# 戻り値は ["fish", "beef", "banana","potato"]