What's the best way to customize ruby ​​gems for reading code

To understand the source code of various gems, I often want to put different puts statements in the source code, or even try to use the ruby ​​debugger.

But what is the best way to do this?

You clone the project from github and make changes locally, if so how do you "force" the local cloned code on top of a local gem on your machine. Am I just creating some scripts explicitly requiring the path to the cloned repository folder?

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

Are there any other methods that don't count? How does this change for gems intended for use in rails projects.


source to share

3 answers

This is how I usually do this when I want to make changes to the Gem:

  • Embed the repository to Github
  • Check it out and create a new branch for local changes.
  • Use Bundler to manage dependencies for a project that uses a Gem
  • Change one line in Gemfile

    to use the forked version of Gem:

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



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


c /path/to/thegem

is the path to your local working copy.

The advantage is that you already have the perfect infrastructure set up to push your changes with a pull request :)



With Bundler .

In your Rails app, just edit the Gemfile and add:

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


PS: Bundler will work with any Ruby project.



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


  • gem install gemedit


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


All Articles