robodisco
robodisco

Reputation: 4282

Whats the best way to tweak ruby gems for code reading

To help understand the source code of various gems I often want to place various puts statements in the source code or even try using the ruby debugger.

But whats the best way of doing this?

Do you clone the project from github and make changes locally, if so how do you "force" the use of the local cloned code over the local gem on your machine. Do I just create some scripts that explicitly require the path of the cloned repos folder?

Or do should I use rvm to create a temp gemset, download the gem and modify it directly?

Are there any other methods ive overlooked? How would this change for gems designed for use within rails projects.

Upvotes: 3

Views: 434

Answers (3)

DungHuynh
DungHuynh

Reputation: 118

You can use rvm to create a temp gemset, download the gem and modify it directly. A fast way to view/modify a gem is using gemedit :

Install:

  • gem install gemedit

Usage:

  • gem edit devise
  • or: gem edit devise -e mate

Upvotes: 1

Niklas B.
Niklas B.

Reputation: 95318

The way I usually do it when I want to make changes to a Gem:

  1. Fork the repository on Github
  2. Check it out and create a new branch for local changes
  3. Use Bundler to manage dependencies for the project which uses the Gem
  4. Change one line in the Gemfile to make it use the forked version of the Gem:

gem "thegem", :git => "git://github.com/name/thegem.git", :branch => 'mybranch'

or

gem "thegem", :git => "file:///path/to/thegem", :branch => 'mybranch'

with /path/to/thegem being the path to your local working copy.

The advantage is that you now already have a the perfect infrastructure set up for contributing your changes through a pull request :)

Upvotes: 3

byterussian
byterussian

Reputation: 3609

With Bundler.

In a Rails app simply edit the Gemfile and add:

  gem "gem_name", :path => "~/MyGems/gem_name"

PS: Bundler work with any Ruby project.

Upvotes: 3

Related Questions