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 1 year has passed since last update.

mapメソッド(Ruby)

Posted at

Ruby3.0.0
Arrayクラスmap
mapメソッドは配列を返す

#配列の値全てに数式を入力(nは変数)
a[0,1,2]
a.map{|n| n + 1} # => [1,2,3]

#配列の値全てを文字列に変換する
a.map(&:to_s)

#n個✖️nの配列に特定の値(0)を入力する
n = 2
a = Array.new(n).map{Array.new(n,0)}
puts a
# => [[0,0],[0,0]]
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?