3
3

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.

引数をすべて受け取る仮引数

Posted at

メソッド定義の仮引数に*を付けておくと引数の残りすべてを受け取ってくれる。これに関してこんな書き方ができるのを最近知った。

def foo(*)
end

foo(1, 2, 3)

引数が消えてしまうわけではないらしい。

class Foo
  def foo(*args)
    args
  end
end

class Bar < Foo
  def foo(*)
    super
  end
end

Bar.new.foo(1, 2, 3) #=> [1, 2, 3]

キーワード引数には**が同様に使える(?)。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?