我想写一个Ruby递归函数,但我不断收到此错误。我的代码是这样的“意外结束”错误
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
以下错误消息出现在最后end
声明指出:
语法错误,意想不到的$结束,预计keyword_end
在哪里问题在这里?
这段代码看起来不错。你需要发布整个模块。 – Thomas
看起来不错,但有一个缩进问题。尝试红宝石-w给你警告这些。 – pguardiario