[Ironruby-core] IronRuby internals - How can I get the full path to the current file?
Orion.Edwards at gallagher.co
Tue Jan 3 17:01:58 EST 2012
I thought I'd be a good samaritan and implement require_relative in
IronRuby, but I'm having real trouble figuring out what the current file's
path actually is.
The closest I've got is something like this:
* Pull apart the the caller/backtrace to get the file name
* File.expand_path(file, File.dirname(dir))
* require that file
This is equivalent to the existing ruby idiom of "require
File.join(File.dirname(__FILE__), 'lib/file1')", but this doesn't work
reliably because __FILE__ is already relative, so File.dirname(__FILE__)
often just returns "."
Without the full path to the current file however, this is as good as we
I've looked through various parts of the IronRuby source code...
- as far as I can tell the Parser/Syntax tree code (which has access to
the file path) doesn't keep the information around
- and even if it did, I'm not sure how regular ruby code could access the
If anyone could help at all, even with a small bit of detail, it'd be much
Here's my test program, which works correctly in MRI 1.92, but I cannot
get it to work in IronRuby
Other things I tried
- eval("__FILE__") - is hard-coded to return "(eval)"
- I thought about poking around in RubyContext.Loader.LoadedFiles, but the
Loader doesn't know about the entry-point file (is this a bug??), which is
a big stumbling block
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Ironruby-core