Michael Neumann
10/17/2004 6:05:00 PM
On Mon, Oct 18, 2004 at 12:47:24AM +0900, Kevin Watt wrote:
> Hi Rubyers
>
> Does ruby keep a list of require'd files anywhere? I'd like to make a
> method that will loop over them, check the last modification time to see
> if they've, and reload them if they have.
I did that (or something very similar) yesterday for my webframework,
where a auto reload feature can be quite useful.
$LOADED_FEATURES and $LOAD_PATH is your friend.
# autoload.rb
START_TIME = Time.now
Thread.new {
file_mtime = {}
loop do
sleep 1
$LOADED_FEATURES.each do |feature|
$LOAD_PATH.each do |lp|
file = File.join(lp, feature)
if File.exists?(file) and File.stat(file).mtime > (file_mtime[file] || $START_TIME)
file_mtime[file] = File.stat(file).mtime
p "reload #{ file }"
load(file)
end
end
end
end
}
Regards,
Michael