This post originated from an RSS feed registered with Ruby Buzz
by Daniel Berger.
Original Post: Ruby, Windows and Pathnames
Feed Title: Testing 1,2,3...
Feed URL: http://djberg96.livejournal.com/data/rss
Feed Description: A blog on Ruby and other stuff.
Naturally, it works properly if I replace the path with "C:/foo/bar/baz.rb". But, you know what? That isn't a valid Windows path, even if Ruby does handle it properly.
The more I think about it, the more I think it was a mistake to make Ruby understand forward slashes in path names on Windows. In what was undoubtedly a "seemed like a good idea at the time" moment, there is simply too much inconsistency with many of the core classes and methods when it comes to native Windows paths.
This becomes especially obvious when one starts mucking about with UNC paths, even when using forward slashes. Consider:
Technically, that's a bug. The leading double slash should be retained because it's part of the root.
So, how do we keep Ruby cross platform then with regards to paths? The solution I've taken with win32-file is to temporarily replace all forward slashes with backslashes (if present) and use native Windows methods for path handling. Then, if forward slashes were used, the result is given back in that form.
That's a pain, though, and I'm beginning to think the onus of proper pathnames should have been placed on the programmer, rather than trying to Do The Right Thing because, in some cases, the Right Thing doesn't happen anyway.