我了解以下代码中发生的所有内容,但该部分除外while output
:
1 def doUntilFalse firstInput, someProc
2 input = firstInput
3 output = firstInput
4
5 while output
6 input = output
7 output = someProc.call input
8 end
9
10 input
11 end
12
13 buildArrayOfSquares = Proc.new do |array|
14 lastNumber = array.last
15 if lastNumber <= 0
16 false
17 else
18 array.pop # Take off the last number...
19 array.push lastNumber*lastNumber # ...and replace it with its square...
20 array.push lastNumber-1 # ...followed by the next smaller number.
21 end
22 end
23
24 alwaysFalse = Proc.new do |justIgnoreMe|
25 false
26 end
27
28 puts doUntilFalse([5], buildArrayOfSquares).inspect
我大部分都理解while
,但由于某种原因,我无法通过这段代码中的树木看到森林。有人可以解释while output
第 5 行和第 8 行之间发生了什么。我毫不怀疑它非常简单,但我已经碰壁了。非常感谢任何帮助。