blake.app

Rescue with do/end blocks

Sometimes you just get used to writing ruby a certain way, but often with each release of ruby there are some new features that get released that make your code a bit cleaner. One of those updates to ruby is the ability to rescue with do/end blocks in ruby. In a recent commit I made a co-worker graciously reminded me of this feature which has been around since ruby 2.5.

This means that instead of

begin
  User.transaction do
  ...
  end
rescue
  ...
end

I can just do

User.transaction do
  ...
rescue
  ...
end

So much cleaner.

1 Like