This is what's up:
It seem I've got a syntax problem. Both of the following methods, which are similar to one another, load to irb fine. When I go to use them, though, they produce errors. Since I'm just learning this, I'm not only looking for a fix, I'm looking to understand why both return errors and how any fix works to solve the issues.
Thanks for the help,
TJ
First method:
def sum(*)
i = 1
total = sum[0]
until sum[i] == nil
total = total + sum[i]
i += 1
end
puts total
end
Upon loading this file irb returns => nil
, no errors. However, an attempt to use the method looks like:
sum 3, 58, 298, 2
Unknown error.
Writing the method directly in irb vs loading .rb file produces this error after line 3:
def sum(*)
.. i = 1
.. total = sum[0]
(eval):2: (eval):2: compile error (SyntaxError)
(eval):2: syntax error, unexpected $end, expecting kEND
total = sum[0]
^
Now, I see that it says SyntaxError
but I do not know what the rest of the feedback means nor what proper syntax for this would be.
Second method:
def sum(*)
i = 1
total = sum[0]
until i == sum.count
total = total + sum[i]
i += 1
end
puts total
end
This one produces all the same errors in the same ways as the first.