Catch the obvious bugs earlier
Of course, everyone has really good test suites, don’t you? So when we use invalid syntax, the test suite will catch it. But there is a better, faster, more thorough way to detect these errors.
We have a build step on our continous integration server that checks all ruby source files in the project for syntax errors in under five seconds. It is run before the test suite. Because the earlier you catch a bug, the lower the costs of fixing it.
If you use git, I also recommend a pre-commit hook that checks all staged ruby source files before you can commit them - so the bugs are caught even earlier.
We achieve this using a small script that integrates the ruby syntax checker (ruby -c) into our workflow at several levels. Without parameters, the script checks all ruby source files in the current directory and its subdirectories recursively and in parallel, using all your cores. This is how it’s used on the CI server.
But the script has two additional modes:
-c : to only check files with unstaged changes
-s : to only check staged files
Use -s for the pre-commit hook. It’s so fast you won’t notice it - and you will never accidentally commit code with invalid syntax again.