Gem of the week: Rubocop
Clean that code up!


Dead or alive, you’re coming with me, terrible ruby style!

Luckily the Prime Directives don’t prevent Rubocop from helping us clear our offenses in our Rails projects. Two lines of code and you’ll be able to start clearing your name for your many crimes against the community ruby style guide.

Rubocop understands that as deadlines loom, multiple hands touch the code, and code review rip apart your hard work that it’s easy to let styling take a back seat to getting something out for the deploy/demo/meeting. A few offenses here and there are ok but as they add up it can really begin to affect the quality and readability of your code, not to mention the performance in some cases.

All you have to do is add 

gem ‘rubocop’, require: false

to your gemfile and run 


in the root directory of your Rails project to have Rubocop crackdown.

Rubocop shows you in an easy to parse list, very similar to Rails tests, all the lines of code that disregard the community Ruby style guide which is curated and contributed to by Ruby users like you and me. A few examples of offenses Rubocop can levy against you are shown below.









Are these changes going to increase the performance of your code ten-fold? No. Are these offenses really that big of a deal? Probably not. Though, Rails is convention over configuration though so why not adhere to the most popular Ruby style guide so our code can be clean, readable, and consistent for ourselves and others that may look at the code after you.

Leave a Reply