Robert Klemme
1/20/2009 10:47:00 AM
2009/1/20 timr <timrandg@gmail.com>:
> Hi guys/gals,
> I am trying to write a method to give the full paths of all files
> loaded into a program when a require statement is executed.
> I would like to be able to get the same result each time a "require
> 'file'" statement is executed. To do so, I need to get the $"
> back to the state it was in prior to the require command being
> executed. But alas it is read only and does not allow me to redefine
> it.
> Anyone know how to override a read only setting or circumvent this
> somehow.
As far as I can see you do not need that. You can do this:
#!/bin/env ruby
def require_logged file
old = $".dup
if require file
($" - old).each do |loaded_file|
full = nil
$:.each do |path|
full = File.join(path, loaded_file)
break nil if test(?r, full)
end and raise "Could not find file #{loaded_file}"
puts "loaded #{full}"
end
end
end
p require_logged('socket')
p require_logged('socket')
Kind regards
robert
--
remember.guy do |as, often| as.you_can - without end