DEV Community

Discussion on: Methods, blocks and sorting in Ruby

Collapse
 
lysofdev profile image
Esteban Hernández

Great post! Ruby is my favorite language when it comes to syntax. Unfortunately, I work in a Java place :'( BTW the return keyword in Ruby is optional since Ruby will return whatever the result of the last statement in a method is implicitly. However, we can use return to end method execution early like in an edge case where we want to stop from completing the method. One last thing about return, it only affects methods, not blocks or lambdas so returning from a block or lambda will actually return the method that is calling the block or lambda itself.

Collapse
 
damcosset profile image
Damien Cosset

Return is optional ? Sweet ! Thanks!!

Collapse
 
rhymes profile image
rhymes

Ruby is my favorite language when it comes to syntax. Unfortunately, I work in a Java place

I'm sure JRuby isn't going to fly but maybe you can find a compromise in Kotlin? I don't know much about it, I'm just mentioning it because it might provide you a happier experience while being able to keep your job :D