Are Ruby Errors Wrong?

The return keyword is optional in ruby, so for functions with only one exit point, the "return result" can safely be replaced simply with "result".

Are there any Ruby recommendations for doing this?

I try to avoid the return keyword as much as possible due to their uncontrolled behavior in procs.

+7
source share
1 answer

"return" in ruby โ€‹โ€‹is only used if you are trying to return more than one value. eg.

return val1, val2 

or if it makes sense to return earlier from the function, for example.

 #check if needed param is set return if !param #some operations which need param 

which is easier than messing up your code with cascading if statements.

Conclusion: use return every time it simplifies your code, or it makes understanding easier.

+19
source

All Articles