|
|
|
|
|
by vidarh
3010 days ago
|
|
Actually, in Ruby we have "ensure" def foo arg
return true if arg == 42
puts "got past the guard"
raise "blah"
ensure
puts "ensure always"
end
foo(42)
foo(3)
The "ensure" blocks gets executed whether or not you return early, throw exception or return at the end of the block. |
|
All make the "goto manual cleanup at end" less necessary, and make early return easier to use.