Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the asterisk alone in the parameter list?

Tags:

ruby

I found this in a Module that is supposed to extend some other class:

module Somemodule
  def foo(*)
    do_something_funny
    super
  end
end

I understand def foo(*args) construct. What is the purpose of an asterisk alone?

like image 541
Carlos Troncoso Avatar asked Jan 28 '26 05:01

Carlos Troncoso


1 Answers

It's similar to *args but you get no reference to the arguments. They are, however, passed as provided to any super invocation to the parent's constructor (or same-name method), as long as no explicit parameters are specified in the super call.

It is a nice way to convey that you do not intend to process the provided arguments in any way.

like image 168
Kostas Rousis Avatar answered Jan 30 '26 11:01

Kostas Rousis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!