I didn’t realise you could do this, from a Ruby or Rails project using bundler/Gemfile:

bundle open activerecord

Then it opens the source code for that gem (activerecord in this case), using the version specified in your Gemfile.lock.

Thanks to Justin Weiss for this tip, from his weekly email.

You can specify your favourite editor in your ~/.bash_profile (or similar). E.g., for Sublime Text:

export EDITOR='subl -w'

(NB: -w makes it wait for the files to be closed before returning. This is worth doing, as some commands will pause until control returns, and then continue, for example, git commit.)