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

引数の種類

0
Posted at

引数の種類

一言に引数といっても様々な種類の引数が存在します。
その中から3種類について書きます

デフォルト引数

代入するオブジェクトがなかった場合はデフォルトで指定した値が代わりに代入される。
記述は以下

def initialize(name="Tanaka")
end

可変長引数

可変長引数は引数の数に制限を設けていない引数のこと。
その引数は配列として認識される。
記述は以下

def initialize(*name)
end

キーワード引数

引数にキーを設定して置くことで、誤った値が代入されないように設定することができる。
キーに値が入っていないと
ArgumentErrorが発生する

def initialize(name: "Taro")
end

引数の特性について知ることで値を扱いやすくなりますね

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?