Archive for June, 2008

Useful ActiveSupport::Dependencies

It is quite handy to use rails’ auto-loading functionality on a non-rails ruby project. For e.g. if you want the classes in your lib folder to be auto-loaded, the following piece of code will help:

require 'active_support'
Dependencies.load_paths << "#{File.join(File.dirname(__FILE__), 'lib')}"

Say you have a file lib/answer.rb which defines class Answer; end;. This will be required when you first use Answer constant in your code.

Comments