-- Leo's gemini proxy

-- Connecting to gemlog.blue:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini

Note: This post is a Gemini space version of my post originally published on December 4, 2020

https version of this post


I had finished writing a piece of software in Ruby in for Linux and wanted to test it also on PC. Since the software involved reading in some data from files, I wanted to be sure that the pathnames could be handled on PC.


In Lisp, this is handled with relative ease where it's possible to specify the subdirectory of interest, and the file(s) within that, and it's up to the Lisp implementation to handle the differences between different operating systems.


I was rather expecting something similar for Ruby (given its influence from Lisp), but to my surprise, the official documentation on the File class had no information that I could find as to how pathnames would be handled differently on different operating systems.


Then I looked at the docs for the Ruby IO class

[https] Ruby 2.7.2 IO class


and I found the information there. It says:


> Ruby will convert pathnames between different operating system conventions if possible. For instance, on a Windows system the filename "/gumby/ruby/test.rb" will be opened as "\gumby\ruby\test.rb". When specifying a Windows-style filename in a Ruby string, remember to escape the backslashes


This was wonderful news, and I was thrilled that I didn't have to alter any of my functions to make my software work on PC. But I was puzzled that this sort of info wasn't more prominently displayed on other pages where a file path is highly likely to be the argument of a function (e.g. in the docs for the File class).


Anyhow, I noted this down here just in case a) I need the information again and forget where to find it or b) in case anyone else was looking to do something cross-platform and searching for this sort of information.

-- Response ended

-- Page fetched on Sun Jun 2 10:14:15 2024