Iñaki Baz Castillo
4/3/2009 10:00:00 PM
El Viernes 03 Abril 2009, Elias Orozco escribi=C3=B3:
> I=C3=B1aki Baz Castillo wrote:
> > El Viernes 03 Abril 2009, Elias Orozco escribi=C3=B3:
> >> I haven't require yet. So can anyone help or give me any hint on how to
> >> load them all dynamically and deal with those dependencies?
> >
> > path =3D File.dirname(__FILE__) + "/files_dir"
> >
> > require "#{path}/required_file1"
> > require "#{path}/required_file2"
> > require "#{path}/required_file3"
> >
> > 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:
=2D--------------------------
failed_files=3D[]
path =3D 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
=2D---------------------------
(It should be very improved however).
=2D-=20
I=C3=B1aki Baz Castillo <ibc@aliax.net>