After consideration, I changed my proposal.
- Rename
#absolute_path
to #real_path
(or #realpath
) and make #aboluste_path
as alias of #real_path
.
- change
absolute_path
(real_path
) on eval
with given file name.
summary of current behavior¶
On MRI, "path" is used several ways.
__FILE__
-
caller(_locations)
, backtrace
-
requre_relative
(base directory)
$0
And ISeq has path
and absolute_path
. I use this terminology.
- path: given path.
- absolute_path: realpath(path) if path is exist. If not, it is nil.
Above usages are implemented with path
and absolute_path
.
-
__FILE__
# path
-
caller(_locations)
, backtrace # path
-
requre_relative
(base directory) # absolute_path
-
$0
# path
Most of case, path and absolute_path is same. However, the following case they are not same.
-
path
and realpath(path)
is different because of symlink (absolute_path
is realpath).
- script name is given by command parameter (
ruby x.rb
) (absolute_path
will be /path/to/x.rb
).
-
eval()
without file name (path
will be "(eval)" and absolute_path
will be nil).
Note that eval(script, binding, "x.rb")
makes path
and absolute_path
return "x.rb"
even if given file name is not realpath.
eval('caller_locations(0, 1).each{|e| p [e.path, e.absolute_path]}')
eval('caller_locations(0, 1).each{|e| p [e.path, e.absolute_path]}', binding, 'x.rb')
["(eval)", nil]
["x.rb", "x.rb"]
proposal¶
Checking current behavior, #absolute_path
is used as realpath
(check the existing and resolve symlink). So I want to add #realpath
or #real_path
. I'm not sure which is better because there is File#realpath
and absolute_path
include _
.
Also I want to check realpass for file name given at eval()
. If file name is not existing, #realpath
should be nil
. In this case, require_relative
should fail because MRI can't infer the base directory.
How about it?