Lets learn return


array cant be coerced into fixnum

def add (n,*x)
      return (n + x)

output = add(2)
output += 2
puts output

but it gives me the way to go green light to move on to next exercise...what seems to be the issue?


If you use the so-called splat-operator in your function-parameter like *x
the RUBY-interpreter will expect you to use multiple arguments
and treat these arguments as an Array of Values

Read this
== discussions / opinions ==

You will then have to use

def add (n,*x)
      return (n + x[0])

output = add(2,2)
#output += 2
puts output

as your code.....


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.