gpt4 book ai didi

ruby - ruby脚本中的语法错误(意外的keyword_end和意外的$ end)

转载 作者:行者123 更新时间:2023-12-03 08:16:01 24 4
gpt4 key购买 nike

我正在编写一些代码来解决编程问题。我刚刚在解决方案中引入了一个新功能,这导致以下错误。请注意,没有此功能将不会出现错误。

search.rb:48: syntax error, unexpected keyword_end
search.rb:68: syntax error, unexpected $end, expecting keyword_end

我意识到这是由末端间隙造成的。我只是找不到。 (我已经用注释标记了第一个错误的位置。第二个错误是代码的最后一行,此处未显示。)
def processing_function
qcount = pcount = $n
qstrength = 0
$query_hash.each do |qkey, qvalue|
print "Q",qkey,": "
$page_hash.each do |pkey, pvalue|
qvalue.each_index do |i|
pvalue.each_index do |j|
if qvalue[i]==pvalue[j]
qstrength = qstrength + qcount*pcount
end
pcount--
end #** This is line 48. First error occurs here. **#
qcount--
pcount=$n
end
if qstrength!=0
print "P",pkey," "
end
qstrength=0
end
print "\n"
end
end

最佳答案

Ruby没有--++运算符。使用例如+= 1代替。

There is short article about differences for C/C++ and Ruby

关于ruby - ruby脚本中的语法错误(意外的keyword_end和意外的$ end),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15699413/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com