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
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 May 31, 2016 return 能省就省
|
2
ChiangDi May 31, 2016 via Android lisp 继承过来的吧,最后一个表达式作为返回值
|
3
msg7086 May 31, 2016 因为如果你遵照最佳实践的话,你会发现最末的 return 是毫无必要的,徒增无用代码量。
(因为一个方法一般不会超过 10 行。) |