Ruby Developer Notes Useful things

23Jun/101

Cross version Ruby debug with ruby-debug-wrapper

When you debuging Rails 3 application (which uses Bundler) and trying different ruby versions with RVM you have following problem: you should switch your Gemfile between ruby-debug and ruby-debug19 gems to work with 1.8 and 1.9 Rubies. ruby-debug-wrapper gem solves the problem.

Follow this steps:

  1. Install ruby-debug gem for each ruby version you will use. For example:
    [cc lang="bash" width="670"]
    # rvm use system
    # gem install ruby-debug
    # rvm use ree@rails3
    # gem install ruby-debug -- --with-ruby-include=$rvm_path/src/ree-1.8.7-2010.02/
    # rvm use ruby-1.9.2-head@rails3
    # gem install ruby-debug19 -- --with-ruby-include=$rvm_path/src/ruby-1.9.2-head/
    [/cc]
  2. Add to Gemfile following line
    [cc lang="ruby"]
    gem 'ruby-debug-wrapper', :group => :development
    [/cc]
  3. Run bundler
    [cc lang="bash"]
    # bundle install
    [/cc]
  4. Now you can run server with debugger and switch ruby version without changing Gemfile each time:
    [cc lang="bash"]
    # rvm use system
    # script/rails s -u
    # rvm use ree@rails3
    # script/rails s -u
    # rvm use ruby-1.9.2-head@rails3
    # script/rails s -u
    [/cc]

Possibly my solution is still raw. So waiting for your comments and bug reports. Hope this can save few minutes to someone.

P.S.
Few days after i have found more simpler solution. You can just include following lines to your Gemfile:
[cc lang="ruby"]
if RUBY_VERSION < '1.9' gem 'ruby-debug' else gem 'ruby-debug19' end [/cc] So i was on the wrong way. 🙂

Comments (1) Trackbacks (0)
  1. I think Bundler ‘platforms’ are intended for this – you can do something like:

    gem ‘ruby-debug’, :platform => :ruby_18
    gem ‘ruby-debug19’, :platform => :ruby_19

    More info here: http://gembundler.com/man/gemfile.5.html


Leave a comment

No trackbacks yet.