Ruby 这个while循环的条件是什么?

Ruby 这个while循环的条件是什么?,ruby,while-loop,Ruby,While Loop,我正在阅读Chris Pine的,在中遇到了这个奇怪的代码片段: def doUntilFalse firstInput,someProc 输入=第一次输入 输出=第一次输入 而输出 输入=输出 输出=someProc.call输入 结束 输入 结束 buildArrayOfSquares=Proc.new do |数组| lastNumber=array.last if lastNumberwhile output表示运行循环,直到while具有除false或nil以外的任何值。正如在Ruby

我正在阅读Chris Pine的,在中遇到了这个奇怪的代码片段:

def doUntilFalse firstInput,someProc
输入=第一次输入
输出=第一次输入
而输出
输入=输出
输出=someProc.call输入
结束
输入
结束
buildArrayOfSquares=Proc.new do |数组|
lastNumber=array.last

if lastNumber
while output
表示运行循环,直到while具有除
false
nil
以外的任何值。正如在Ruby中一样,除了这两个值之外,所有的值都是真实值。

但是,它不等于while output==true吗?但是,当我使用后者运行代码时,我不会得到相同的结果。
而output==true
只有在
output=true
时才为true。但是如果
output=1
呢?你的情况变得不正确。但是,如果输出为
,而输出为
时,对于
output=1
,它仍然保持true(truthy)。所以不同了。啊,现在我明白了!谢谢!:)不遵循Ruby命名约定的Ruby教程。我希望他在书中把这个问题解决了。。。
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