> but Ruby often shies away from doing that. My interpretation is that they prefer to return _something_ rather than blowing up, so the show can go on.
There are two (intertwined) explanations:
- In Ruby exceptions are costly to generate.
- Similar to Go, Ruby's stdlib design favours using return values for signalling, keeping exceptions for exceptional cases.
So in plain† Ruby there are a lot of places that use `nil` to signal that something's off, e.g `[1,2,3][4]` returns `nil` because it's an out of bounds access, or `"123".downcase!` returns `nil` because nothing has been downcased, or `__FILE__` returns `nil` when a file is `eval`'d.
So yes, you have to check for things like `nil` (or explicitly swallow with `&.` which is kind of a Maybe monad pattern) before doing stuff with values, just like you check for `if err == nil` in Go.
Running a type checker like `steep` helps a lot linting for these cases.
† Rails likes to generate exceptions, but Rails != the whole of Ruby.