我是通过克里斯·派恩的Learn to Program读,我遇到了Chapter 10: Blocks and Procs这个奇怪的代码片段:这个while循环的条件是什么?
def doUntilFalse firstInput, someProc
input = firstInput
output = firstInput
while output
input = output
output = someProc.call input
end
input
end
buildArrayOfSquares = Proc.new do |array|
lastNumber = array.last
if lastNumber <= 0
false
else
array.pop # Take off the last number...
array.push lastNumber*lastNumber # ...and replace it with its square...
array.push lastNumber-1 # ...followed by the next smaller number.
end
end
什么正在检查的条件,在上述while循环?它似乎不是while output == true
的简写。
Ruby教程不遵循Ruby的命名约定。我希望他在书中解决这个问题...... – spickermann