It ’ s best practice to use the implicit return, and only include return explicitly when you ’ re returning a line that ’ s not at the end of the method.
def three_plus_two
return 3 + 2
end
best practice:
def three_plus_two
3 + 2
end
1
kikyous 2016-05-31 16:48:36 +08:00 1
return 能省就省
|
2
ChiangDi 2016-05-31 16:50:29 +08:00 via Android 1
lisp 继承过来的吧,最后一个表达式作为返回值
|
3
msg7086 2016-05-31 21:13:35 +08:00 1
因为如果你遵照最佳实践的话,你会发现最末的 return 是毫无必要的,徒增无用代码量。
(因为一个方法一般不会超过 10 行。) |