Lets learn return


#1



array cant be coerced into fixnum


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

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?


#2

@simssima,
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 ==
http://stackoverflow.com/questions/3701264/passing-a-hash-to-a-function-args-and-its-meaning

You will then have to use

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

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

as your code.....


#3

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