3 June 2012

A Gem hack in Rails 3 project

I have a little project, one piece of the main function requires some help from a gem named 'HelloWorld'. However, this gem doesn't have the exact support I need. Before the owner of the gem accept my github pull request, I need do some hack to extend two of the the gem's classes 'Hello' and 'HelloWorld'.

I put the class "Hello" in a file named 'hello.rb', placed the file in the 'lib',
and 'autoload' the 'lib' directory by putting in the following line in the 'Application.rb' file:
config.autoload_paths += %W(#{config.root}/lib)
It worked like a charm! I can invoke the class method of my "Hello" class in Rails Console! Hooary!