We’ve been using this great tool in the Da Vinci Coders class called guard-rubocop. It’s a gem for ruby that checks your code for conventions and good code grammar (is that a legit term?). Anyway, I’ll walk through how to install rubocop for a particular directory on your computer.

First, in your terminal, navigate to the directory where you want rubocop to patrol. I wanted to install it in my homework_assignments folder, so for me, this looks like:

$ cd workspace/davinci_coders_t2_2014/homework_assignments

Now, I like to do as much as I can from the terminal, so i typed

touch Gemfile

This creates a file called Gemfile, which is where your computer will look to find specific gems that you want to install. open the Gemfile in whatever text editor you use (I use Ruby Mine) and type the following:

Save the file and go back to your terminal. In the terminal type


This will look for the Gemfile, and install the gems listed in it.

One last step, which is to initialize guard by typing

guard init

You can then run guard in the terminal from the directory in which it is installed, and it will detect any offensive violations in any of your ruby files within that directory.


The problem that I have encountered is that sometimes when I go back to that directory and try to run guard, it seems to not know what I’m talking about. I don’t know why this happens, but I think I’ve found a fix to this, which is to type



bundle update

Any insight on why guard seems to forget that it’s there would be appreciated. Thanks!


About Aaron Glasenapp

I am a freelance Web/Rails developer and a hard core recreational mathematician.

3 responses to “Rubocop”

  1. Jason Noble (@jasonnoble) says :

    Hey Aaron, you probably need to tell RVM what version of Ruby to use and what gemset to use within the homework_assignments directory. That way when you cd into that directory, RVM will automatically switch to the have the right gems installed.

    • Aaron Glasenapp says :

      Thanks Jason! I have a question about that. My notes say to make rvm use a specific gemset for a given directory to do the following:

      echo ‘name_of_gemset’ > .ruby-gemset

      However, when we did this, we typed

      echo ‘lrthw_exercises’ > .ruby-gemset

      lrthw_exercises is not the name of a gemset, but the name of the directory. So for the homework_assignments folder, should I type

      echo ‘homework_assignments’ > .ruby-gemset

      or something else, like

      echo ‘guard-rubocop’ > .ruby-gemset

      • Jason Noble (@jasonnoble) says :

        The gemset name can be anything you want. Our convention so far is to use the directory name as the gemset name.

        So for the homework_assignments folder, you could use ‘homework_assignments’ or ‘guard_rubocop_gemset’. It’s just a name…


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: