Crystal: Std lib: File.absolute? File.relative? missing

Created on 5 Oct 2017  路  5Comments  路  Source: crystal-lang/crystal

Hi, I just found out that there is no native way in Crystal how to detect if given path is absolute or relative. Naive solution is to call path == File. expand_path(path), but I can't verify if it works in all cases and all OS.

My opinion is, that functions like this should be in std lib.
I can try to collaborate on that with some guide.

Most helpful comment

Personally I think this part of the stdlib should be rearranged, all of the File.* methods which deal with actual path strings should be moved to a Path class (and we should actually be able to instantiate a Path and add them together, which enables some neat things). Perhaps i'll write a detailed proposal soon...

All 5 comments

These methods conceptually belong to Pathname (as in Ruby), which doesn't exists in Crystal (yet). Adding them to File would look weird since it's not the _file_ which is _relative/absolute_, but its path.

but I can't verify if it works in all cases and all OS.

making sure the std::method is written in a way that it ensures it worked would be even better?

Personally I think this part of the stdlib should be rearranged, all of the File.* methods which deal with actual path strings should be moved to a Path class (and we should actually be able to instantiate a Path and add them together, which enables some neat things). Perhaps i'll write a detailed proposal soon...

@monouser7dig because Windows arent yet supported, then I should not be worried :) For some reason I was thinking Windows are already supported, but PR is still in progress.

ah I see, although this may be the least of your win problems :)
(disclaimer I have not tested it on win)

... if the issue will be resolved by pure evolution there may not be a need for

native way in Crystal how to detect if given path is absolute or relative

Was this page helpful?
0 / 5 - 0 ratings