Reputation: 7728
I am trying to write a Ruby recursive function, but I am getting this error continuously. My code goes something like this
def myfun(mylist)
nextlist = []
if mylist.size == 1
return (mylist[0])
else
# populate the list "nextlist" with fewer elements as compared to mylist somehow
end
return myfun(nextlist)
end
The following error message comes up pointing at the last end
statement:
syntax error, unexpected $end, expecting keyword_end
Where is the problem here?
Upvotes: 0
Views: 136
Reputation: 181735
According to the old "teach a man to fish" proverb, I'll answer the more general question "how do I find a missing or superfluous end
?".
For this, I find it very helpful to use the auto-indenting feature of my editor. In vim, I just hit gg=G to indent the entire file, and scan through it visually to find where the indent starts being different from what I'd expect.
Upvotes: 1
Reputation: 338
I don't get the syntax error when I copy and paste your code. Is there other code around your pasted function that might be missing an end
?
Upvotes: 0