Explicit return from a Ruby method - implementation hiding, reuse and optimisations.
- by Chris McCauley
Hi,
Rather than allowing a Ruby method to blindly return the last statement evaluated, is there any advantage to returning nil explicitly?
In terms of implementation hiding and reuse, it seems dangerous to blindly allow the last expression evaluated to be returned - isn't there a danger that a user will rely on this only to get a nasty surprise when the implementation is modified? Surely returning nil would be better unless an explicit return value was given.
Following on, is there an optimisation that Ruby can make when the return is a simple type rather than a reference to a more complex object?
Chris