TIL: Adding message in a block when raising an error in RoR

Today I learned from my colleague Nicolas how you can pass in a message as a block when raising an error, it is so clean and beautiful.

Check this out:

raise InvalidString, <<~MSG if invalid_string
  #{string} is not valid
  Expected something else!
MSG

Leave a Reply

Your email address will not be published. Required fields are marked *

Copyright Loving to Code 2025
Tech Nerd theme designed by Siteturner