is it possible to override a 'read only' environmental variable like $" ?
- From: timr <timrandg@xxxxxxxxx>
- Date: Mon, 19 Jan 2009 21:38:53 -0800 (PST)
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
.
- Follow-Ups:
- Re: is it possible to override a 'read only' environmental variable like $" ?
- From: Robert Klemme
- Re: is it possible to override a 'read only' environmental variable like $" ?
- From: Brian Candler
- Re: is it possible to override a 'read only' environmental variable like $" ?
- Prev by Date: Re: RubyForge downtime
- Next by Date: Re: 10 numbers in between 2 numbers
- Previous by thread: 10 numbers in between 2 numbers
- Next by thread: Re: is it possible to override a 'read only' environmental variable like $" ?
- Index(es):
Relevant Pages
|