Actions
Feature #21822
closedExpose Return Value in the ensure Block
Feature #21822:
Expose Return Value in the ensure Block
Status:
Rejected
Assignee:
-
Target version:
-
Description
Actions
Added by artemb (Artem Borodkin) 8 months ago. Updated 6 months ago.
Description
Is the variable nil if an exception is raised, even for non-local variable?
By analogy with rescue, it feels natural for me that the variable is unchanged in that case.
For me, ensure => ret looks cleaner, reduces cognitive overhead, and is simply easier on the eyes when reviewing real code.
The structure is easier to parse visually, and the intent is clearer compared to the alternatives.
Also, it doesn’t break any existing behavior — it’s purely additive, just a small but useful extension that makes the code more elegant and pleasant to read.
Thank you for the feedback. I understand the aesthetic appeal, but "cleaner" is subjective, and the existing pattern is already idiomatic Ruby with no real cognitive overhead.
More importantly, "purely additive" does not mean cost-free. Every new syntax must be defined precisely, documented, and handle edge cases correctly. As nobu noted in #3, the semantics when an exception is raised are not obvious, which suggests the concept has rough edges that outweigh the cosmetic benefit.
Matz.