Requiring Ruby standard library packages

After working with Rails so much, it’s easy to forget all the magic it adds to Ruby. A colleague had a question about why the CSV library worked while in a development environment, but failed to in a production environment. After some quick debugging, we discovered that it was simply because the CSV library wasn’t loaded in the production environment. It was likely that a library loaded only during development was requiring the CSV library, thus making it available to use.

It’s probably a good practice to require all the standard library packages needed by code in a project, and not rely on them coming from somewhere else (such as a gem, that might only be loaded in certain contexts). This is certainly something that I have overlooked lately in my own code, as things like CSV, ‘just worked’.