Feature #15868 » 0001-Add-File.absolute_path.patch
file.c | ||
---|---|---|
return rb_file_absolute_path(argv[0], argc > 1 ? argv[1] : Qnil);
|
||
}
|
||
/*
|
||
* call-seq:
|
||
* File.absolute_path?(file_name) -> true or false
|
||
*
|
||
* Returns <code>true</code> if +file_name+ is an absolute path, and
|
||
* <code>false</code> otherwise.
|
||
*
|
||
* File.absolute_path?("c:/foo") #=> false (on Linux), true (on Windows)
|
||
*/
|
||
VALUE
|
||
rb_file_s_absolute_path_p(VALUE klass, VALUE fname)
|
||
{
|
||
VALUE path = rb_get_path(fname);
|
||
if (!rb_is_absolute_path(RSTRING_PTR(path))) return Qfalse;
|
||
return Qtrue;
|
||
}
|
||
enum rb_realpath_mode {
|
||
RB_REALPATH_CHECK,
|
||
RB_REALPATH_DIR,
|
||
... | ... | |
rb_define_singleton_method(rb_cFile, "mkfifo", rb_file_s_mkfifo, -1);
|
||
rb_define_singleton_method(rb_cFile, "expand_path", rb_file_s_expand_path, -1);
|
||
rb_define_singleton_method(rb_cFile, "absolute_path", rb_file_s_absolute_path, -1);
|
||
rb_define_singleton_method(rb_cFile, "absolute_path?", rb_file_s_absolute_path_p, 1);
|
||
rb_define_singleton_method(rb_cFile, "realpath", rb_file_s_realpath, -1);
|
||
rb_define_singleton_method(rb_cFile, "realdirpath", rb_file_s_realdirpath, -1);
|
||
rb_define_singleton_method(rb_cFile, "basename", rb_file_s_basename, -1);
|
spec/ruby/core/file/absolute_path_spec.rb | ||
---|---|---|
require_relative '../../spec_helper'
|
||
describe "File.absolute_path?" do
|
||
before :each do
|
||
@abs = File.expand_path(__FILE__)
|
||
end
|
||
it "returns true if it's an absolute pathname" do
|
||
File.absolute_path?(@abs).should == true
|
||
end
|
||
it "does not expand '~' to a home directory." do
|
||
File.absolute_path?('~').should == false
|
||
end
|
||
it "does not expand '~user' to a home directory." do
|
||
path = File.dirname(@abs)
|
||
Dir.chdir(path) do
|
||
File.absolute_path?('~user').should == false
|
||
end
|
||
end
|
||
it "calls #to_path on its argument" do
|
||
mock = mock_to_path(File.expand_path(__FILE__))
|
||
File.absolute_path?(mock).should == true
|
||
end
|
||
platform_is_not :windows do
|
||
it "takes into consideration the platform's root" do
|
||
File.absolute_path?("C:\\foo\\bar").should == false
|
||
File.absolute_path?("C:/foo/bar").should == false
|
||
File.absolute_path?("/foo/bar\\baz").should == true
|
||
end
|
||
end
|
||
platform_is :windows do
|
||
it "takes into consideration the platform path separator(s)" do
|
||
File.absolute_path?("C:\\foo\\bar").should == true
|
||
File.absolute_path?("C:/foo/bar").should == true
|
||
File.absolute_path?("/foo/bar\\baz").should == false
|
||
end
|
||
end
|
||
end
|
||
describe "File.absolute_path" do
|
||
before :each do
|
||
@abs = File.expand_path(__FILE__)
|
- « Previous
- 1
- 2
- Next »