From: Elias Orozco Date: 2009-04-04T07:31:14+09:00 Subject: Re: Loading classes in order Hey Inaki thanks, I think I'll have to go that way. I wonder if that is how rails does to load classes when the server is initialize. I wandered around the initializer file but couldn't get how it was done. Thanks again, Elias I単aki Baz Castillo wrote: > El Viernes 03 Abril 2009, Elias Orozco escribi坦: >> > >> > Dir.chdir(path) >> > Dir["*.rb"].each do |file| >> > require "#{path}/#{file}" >> > end >> >> Thanks Inaki, but in that example I will have to specify the require >> files and that's exactly what I don't want. A lot of classes will be >> copied into that folder and I can't hard-code all those requires. > > When failing due to a non existing class, Ruby raises a NameError > exception. > Then you can add something as: > > --------------------------- > failed_files=[] > > path = xxxxxx > Dir.chdir(path) > > Dir["*.rb"].each do |file| > begin > require "#{path}/#{file}" > rescue NameError > failed_files << file > end > end > > failed_files.each do |file| > require "#{path}/#{file}" > end > ---------------------------- > > (It should be very improved however). -- Posted via http://www.ruby-forum.com/.