Reputation: 474
Let's say that I need to change the functionality of a certain ruby gem that I need in my rails project. I would like to place all the content of the ruby gem inside the main project.
Is this possible? Are there alternative methods?
Thank you
Upvotes: 1
Views: 178
Reputation: 4515
Another option is to fork gem you are writing about, update it and keep in your repository and then refer to it in your Gemfile.
Of course you may copy the whole source of this gem and put it in dedicated folder inside your app (lib/folder_for_your_gem)
Upvotes: 1
Reputation: 8954
You can do this by "monkeypatching" the specific methods. To do this you need to create an initializer that overwrites the method you want to modify. For examplke create config/initializers/monkeypatch.rb
and overwrite the method:
class String
def inspect
puts "Im monkeypatched!"
end
end
When you then create a string and call inspect youll see that the method has been patched. Also you should be careful using monkeypatching because it can have some unwanted sideeffects, especally when you patch very basic classes like the String or Fixnum class.
Upvotes: 2