Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Wrong number of arguments

  • We have a function that expect two integers. Can we instead pass an array of two integers?
  • Normally no, but there are at least 3 solutions
def f(x, y)
  return x + y
end

puts f(2, 3)
values = [3, 4]
puts values

puts f(values[0], values[1])

# puts f(values)
# Error: wrong number of arguments for 'f' (given 1, expected 2)