How ensure works in ruby

The ensure block’s return value is discarded — it’s just a way to clean up after the function does whatever it’s supposed to (and returns the appropriate value). The reason for this is because it allows you to put several return statements (or raise statements) in different places in the function body, without having to duplicate the cleanup code in different places in the function.

Leave a Comment