Rails beginner
Rails beginner

Reputation: 14504

Ruby what is *args ? An array or? in a method

What is *args or *urls if I write a method like:

def test(*args)
@test = args
end

I have also seen *urls is it an array or? Like options are created with hash options = {}.

Upvotes: 2

Views: 2854

Answers (2)

alex
alex

Reputation: 490133

I believe this is to make the function variadic (i.e. the function's arity is an arbitrary number of arguments).

The type is an Array.

Upvotes: 4

Ivaylo Strandjev
Ivaylo Strandjev

Reputation: 70931

Try this(it should answer your question):

def test *args
  puts args.class
end

test

>> Array

Upvotes: 3

Related Questions