From: Overnight Date: 2002-09-23T21:16:12+09:00 Subject: Re: self-loading scripts (at Ruby's startup time) > |Thanks. Wouldn't it be useful to have some special-name, autoloading > |script? It would be the necessary starting point in defining a standard > |for what happens at Ruby's startup time. > I think this should be an application issue. Since Ruby is a general > purpose language, autoloading startup script that is loaded all the > time is not as useful as it seems. mmm... after reading your message, I decided to definitely put aside my autoload desires and a set RUBYOPT=-re:/wip/ruby/autorun.rb appeared in my AUTOEXEC.BAT :-) Ok, I can live with it, especially since I realized that I was solving an autoload issue using another autoload mechanism :-) The first draft of autorun.rb is probably a collection of Ruby horrors (some of them wanted, since I was doing some experiments with scope rules while I was at it) however here it goes: module AutoRun class CFile def CFile.each(filename,&block) #read a file line by line, skipping #blank lines and comments #no reason to define a class, 'twas just #an experiment if FileTest.exist?(filename) f=open(filename,'r') f.each {|l| l1=l.chomp.sub(/#.*/,'').strip yield(l1) if l1.size>0 } f.close end end end @@dir,@@fname=File.split(__FILE__) def AutoRun.putex(e,msg) puts "#{@@fname}: #{msg}:\n #{e.class}: #{e.message}" end autopathname=File.join(@@dir,'autopath') CFile.each(autopathname) { |l| if FileTest.directory?(l) # puts "Adding #{l}" $:.unshift(l) else puts "#{@@fname}: #{l} is not a valid dir (in #{autopathname})" end } autolibname=File.join(@@dir,'autolib') puts autolibname CFile.each(autolibname) { |l| begin require l rescue Exception => e putex e,"error loading #{l} (in #{autolibname})" end } $:.each {|p| sitecustomizename=File.join(p,'sitecustomize.rb') if FileTest.exist?(sitecustomizename) begin require sitecustomizename rescue Exception => e putex e,"error loading #{sitecustomizename}" else break end end } end I feel like there is something strange/wrong in using @@dir and @@fname to make them visible in AutoRun.putex(), but it works and... it is a different issue, anyway. Think I'll go back and study a little more :-) Bye, Andrea