Skip to content

Instantly share code, notes, and snippets.

@JamesChevalier
Forked from ContrarySheep/rvm-coderunner.md
Created November 13, 2013 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JamesChevalier/7454105 to your computer and use it in GitHub Desktop.
Save JamesChevalier/7454105 to your computer and use it in GitHub Desktop.

Coderunner is an app for OSX that makes it easy to run quick bits of code in a variety of languages. It is perfect for someone just experimenting with a particular language. For working with Ruby, I like to use RVM not only use different versions of Ruby, but also to create very specific gemsets. Getting this functionality to work with Coderunner proved a bit of challenge as the documentation is lacking, so I thought I would post the steps I took.

In this example, I will go through the setting up of a RVM environment for Ruby 1.8.7-p357 with a gemset called "my-gemset". I have already created the gemset for this example using the rvm 1.8.7@my-gemset --create command. It is important to note that the RVM environment must be configured prior to applying the settings to Coderunner.

With the RVM environment setup, the next thing to do is open up the Coderunner preferences and look at the languages. There are quite a few default languages, plus the ability to add more as you see fit. To get Coderunner to use a specific version of Ruby, you can add a new language and specify the run command to use a particular RVM environment. I like to title this new language with any details about the particular RVM environment, so in this example I will create a new language called ruby-1.8.7-p357@my-gemset.

The next step is to enter the run command so that the proper RVM environment is loaded. To do this you need to know the absolute path to the wrapper for the environment that you want to use. On a default RVM installation it should be located in the user's .rvm/bin directory. So the wrapper I will use for this example is /Users/contrarysheep/.rvm/bin/ruby-1.8.7-p357@my-gemset. The entire run command will then be:

[[ -s /Users/contrarysheep/.rvm/bin/ruby-1.8.7-p357@my-gemset ]] && source /Users/contrarysheep/.rvm/bin/ruby-1.8.7-p357@my-gemset

Once you have declared the run command, you may want to also change the syntax mode to Ruby and the file extension to rb just to pretty everything up.

Coderunner Preferences

You should now have the ruby-1.8.7-p357@my-gemset language available in the Coderunner language drop-down menu. Any code you run through this specific language should be run through that particular ruby environment.

Coderunner Test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment