有人为什么我这样写:
ruby-1.8.7-p302 > a = %w( a b c)
=> ["a", "b", "c"]
ruby-1.8.7-p302 > while (i = a.shift) do; puts i ; end
a
b
c
=> nil
Run Code Online (Sandbox Code Playgroud)
这看起来像是通过一个块来.并不是:
while(i = a.shift) { puts i; }
Run Code Online (Sandbox Code Playgroud)
是因为while语法的"do"只是语法糖而且与块的"do"无关?
ruby ×1