在Ruby语言中,以下工作在irb中
for fruit in ['apple', 'banana', 'cherry', 'date'] do
puts fruit
end
Run Code Online (Sandbox Code Playgroud)
但这一个没有
# error
for fruit in ['apple', 'banana', 'cherry', 'date'] { puts fruit }
Run Code Online (Sandbox Code Playgroud)
请注意以下块分隔符不会出错
5.times do |i|
puts "hello "+i.to_s
end
5.times { |i| puts "hello "+i.to_s }
Run Code Online (Sandbox Code Playgroud)
编辑:我猜我所观察到的是与end替代{}的方式不一致有人可以解释为什么或请指出我的错误?