T
timr
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.
Thanks is advance,
Tim
See the code below:
def catch_new_paths(file_to_require)
old = $".dup
require(file_to_require)
new = $".dup
after = new - old
after.each{|file| $:.each{|path| puts path + "/" + file if
File.exists?(path + "/" + file)}}
#at this point I would like to convert the $" variable back to its
state before the require statement was run with
#$" = old
#but doing so results in
# -:7:in `catch_new_paths': $" is a read-only variable (NameError)
end
catch_new_paths("base64")
# >> /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/
ruby/1.8/universal-darwin9.0/nkf.bundle
# >> /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/
ruby/1.8/kconv.rb
# >> /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/
ruby/1.8/base64.rb
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.
Thanks is advance,
Tim
See the code below:
def catch_new_paths(file_to_require)
old = $".dup
require(file_to_require)
new = $".dup
after = new - old
after.each{|file| $:.each{|path| puts path + "/" + file if
File.exists?(path + "/" + file)}}
#at this point I would like to convert the $" variable back to its
state before the require statement was run with
#$" = old
#but doing so results in
# -:7:in `catch_new_paths': $" is a read-only variable (NameError)
end
catch_new_paths("base64")
# >> /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/
ruby/1.8/universal-darwin9.0/nkf.bundle
# >> /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/
ruby/1.8/kconv.rb
# >> /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/
ruby/1.8/base64.rb