ruby - What is the best way to load files from the lib folder that add methods to ~existing~ classes in Rails 3? -


i using config.autoload_paths in way similar related question load classes lib directory in rails 3 project.

specifically, i've added these lines config/application.rb file:

config.autoload_paths += %w(#{config.root}/lib) config.autoload_paths += dir["#{config.root}/lib/**/"] 

however, method not working me existing classes. when add file lib/extensions/string.rb:

class string   def foo     puts "foo"   end end 

i undefined method 'foo' "":stringerror. through various searches i've got sense problem has lazy loading of these files. tried using config.eager_load_paths not able work.

i'm doing exactly describing in application, , difference also have initializer called extensions.rb following code:

dir.glob('lib/extensions/*').each { |f| require f } 

Comments