After being annoyed with running multiple versions of Ruby just by using MacPorts I finally gave in and tried out rvm, the Ruby Version Manager. That stuff got even more annoying when I tried to make Bundler behave well with multiple Ruby versions, because it just doesn't by default. It's not really a problem with normal gems, but Bundler falls apart with its defaults when you're trying to run gems with native extensions. Hint: Set bundle_path to include RUBY_VERSION and make some links from one cache directory to another to not have every gem cached for every Ruby version.

The promise of being able to easily switch between different versions and still having just one ruby binary and not one called ruby1.9 with MacPorts is just neat. While installing them is straight forward, using them from e.g. TextMate is not great. The common solutions of just launching it from the command line or modifying the TextMate Ruby bundle (these changes will have to be made again with the next TextMate update) are not fully acceptable for me, because it still doesn't allow me to switch Ruby versions while TextMate is running. That's one "flaw" rvm has, at least for me. It switches the paths for the Ruby versions for the current shell, it doesn't offer anything to set links in ~/.rvm/bin to the currently active Ruby version, at least as far as I know. No big deal, if it's by design I can live with that, I do think it'd be a nice addition though.

Anyway, I wanted to switch Ruby versions from my shell and have it affect the version I'm using to run my tests from TextMate too. The way to go seems to be rvm <version> --default which will set the default for all other shells. Be aware that it will do what it says, but I could live with that. It's more important to me to be able to make that switch than just having several shells with different versions in each. First step was to shorten that command, because let's face it, that's a lot of text. I added a function to my .zshrc. It should work just as well with bash, but really, you're still using bash?

rvmd() {rvm use $1 --default}

Now you can just rvmd 1.9.1 in your shell prompt and be done with it. Much better.

The other part was telling TextMate what Ruby binary to use. The problem outlined above made that a bit of a pain, so I broke out my shell scripting fu and cranked out this amazing wrapper script, using what rvm already dumps in your rc files:

if [[ -s /Volumes/Users/pom/.rvm/scripts/rvm ]]
  source /Volumes/Users/pom/.rvm/scripts/rvm
`which ruby` $*

Impressive, eh? It just sources the rvm script and then calls the ruby binary that is currently set as default. Make it executable and set a shell variable in TextMate called TM_RUBY and make it point to that script, and you're good to go.

Tags: ruby, textmate

This is the bundle that'll make TextMate almost as good as warm apple pie. RubyAMP comes along with a few additions to Ruby coding in TextMate, but boy do they rock.

Some of its features:

  • Grep for Method
  • Grep for Class/Module, both method and class/module grep use the word under the cursor
  • A much faster (compared to "Find in Project") "Grep in Project"
  • Code completion with data from all open files
  • An intelligent "Go to file" which will try to find something matching the word under the cursor
  • Run RSpec in the debugger

Here's code completion in action:

Picture 2

On the website you'll find a video showing most of the features. Pretty neato. Ruby and Rails development on the Mac just got even sweeter.

Via Samurai Coder.

Today's NetNewsWire tab sweep:

  • DataMapper - Competition for ActiveRecord - Not available at the moment, cached on the Googles.
    Looks like a nice alternative to ActiveRecord, especially for standalone environments without Rails. Being able to put queries, especially simpler ones, in Ruby code is quite appealing.

  • The Great Ruby Shoot-Out
    Antonio Cangiano compared the current Ruby implementations. JRuby, Ruby 1.9 and Rubinius look awesome, at least by the numbers.

  • Upcoming Changes to the JavaScript Language
    I'm still not sure if I'm gonna like what's coming. JavaScript is on the way to turning into a full-blown and statically typed object-oriented language, but with all its pros and cons. It looks a lot like C++, and if that's no a little bit scary, I don't know what is.

  • Google Chart API
    Now that's a really useful API. Put in your data via HTTP request and get back chart images. Awesome.

  • SVNMate
    A TextMate plugin to integrate Subversion, taking the integration further than the Subversion bundle.

  • Rak
    grep in Ruby, ignores .svn and CVS directories. Accepts regular expression in Ruby syntax, and can execute Ruby code on the results.

  • The Evolution of Java
    Right on.

On a side node, Rails 2.0 has been released. I recommend checking out the PeepCode book on Rails 2.0 to check what's new and what's old.

Update: Ryan Daigle (author of aforementioned book) also has a nice collection on a lot of the changes and new features in Rails 2.0.