Tsallaka zuwa abun ciki
Justice Tech School

Variable Arguments

*args collects extra arguments and **opts collects keywords.

Example
def info(first, *rest, **opts)
  "#{first} #{rest} #{opts}"
end
puts info(1, 2, 3, a: 4)
puts [1, 2].push(*[3, 4]).inspect

Result

1 [2, 3] {:a=>4}
[1, 2, 3, 4]

Exercise

Collect keywords.

def f(opts); end

Quiz Test

What does *args collect?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.