How to work with windows paths under UNIX in ruby?

actually I'm a little confused.
Under nix (ubuntu) the script works with different paths, the paths can be as nexopia and Windows.
The Knicks with no problem
nix_path = Pathname.new '/nix/path/ok/file.txt'
nix_path.basename # => <pathname:file.txt> 
nix_path.parent # => <pathname: path nix ok></pathname:></pathname:file.txt>

And with Windows trouble..
win_path = Pathname.new 'C:\win\path\file.txt'
win_path.basename # => <pathname:c:\win\path\file.txt> 
win_path.parent # => <pathname:.></pathname:.></pathname:c:\win\path\file.txt>

The same goes for using File
File.basename 'C:\win\path\file.txt' # => "C:\\win\\path\\file.txt"


How to be?
August 19th 19 at 22:39
1 answer
August 19th 19 at 22:41
Solution
win_path = Pathname.new 'C:\win\path\file.txt'.tr('\\', '/')


And so do conceptual you misuse the Pathname because its implementation is system-dependent. Therefore it is better to use it for the family for current OS paths. And for ways out of your subject areas (Unix/Win/etc) to write separate classes to do so as you need
takto, it's obvious. I was hoping that there are solutions for working with paths, independent of the current OS. But orgogliosa up and down - a decision only his crutches to write, based on the context of the task. What I actually did ) - Althea_Dietrich commented on August 19th 19 at 22:44

Find more questions by tags Ruby