0
我有一个函数可以遍历/遍历一些东西,并且我希望它能够接收一个函数的引用来设置stop_ititeria/do something。 例如,在一类:将对Ruby中方法的引用传递给另一个方法
def a(func_stop,i)
ret = nil # default
while(i < 0)
if (func_stop(@lines[i]))
ret = i
break
end
end
return ret
end
的想法是,我可以传递给函数的引用,有点像Perl的
func1(\&func, $i);
我已经看过,但没能找到这样的事情。 谢谢
'i'不循环内改变? – tokland 2013-03-08 18:30:20
@lines来自哪里? – sunny1304 2013-03-08 18:44:41