Ruby中这些块编码样式的区别或价值是什么?
哪种款式首选?一个与另一个有充分的理由吗?
提前致谢!
1) cmds.each do |cmd|
end
2) cmds.each { |cmd|
}
示例代码:
cmds = [ "create", "update", "list", "help" ]
# Block style one
#
cmds.each do |cmd|
puts "loop1, cmd: #{cmd}"
end
# Block style two
#
cmds.each { |cmd|
puts "loop2, cmd: #{cmd}"
}
茅侃侃
手掌心
月关宝盒
相关分类