Skip to main content

Ruby IO - file pathnames for use on different operating systems

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, and 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.


Popular posts from this blog

How to center images horizontally using Grav

I've been playing around a bit with Grav. I was posing the question to myself: for the relatively simple use-cases I'm dealing with, could it possibly work for my purposes as an alternative to ProcessWire?  The problem I was initially dismayed to find that Grav uses Markdown as its editor, which does not offer native support for horizontal centering of anything (text or images). However, Grav offers some tweaks that help make it easier to do specific things you might commonly want to do. I tried writing a sample article, and I found that one of the hardest things to do was to center an image horizontally. And horizontal centering of images is something I would typically do in most of the articles I would write. So the lack of easy horizontal centering is a highly significant drawback IMHO (most people do want to center images in an article!) However, this issue is made up for by other things in Grav: the relative speed, ease and flexibility of custom theming and built-in suppor...

Life using the Linux operating system exclusively for the last few years

Above: my Linux desktop layout. Back in 2017, I switched my operating system entirely to Linux. In case anyone is wondering, here is what I experienced over the last few years. Others I interact with have no idea I'm on Linux. For example, if someone emails me an MS Word document that I need to complete, I simply open it with LibreOffice (an open-source word processing program that is pre-installed on most Linux systems), edit the document as needed - which is very easy since the same sorts of functionalities are available in LibreOffice - and then I can save it in MS Word format and email it back. Likewise, if I'm on a Zoom call, everything works just the way it does on PC and Mac. Zoom makes their application available for Linux too, I downloaded it and let it self-install, and it works exactly the same way as it does on other operating systems. I can point-and-click my way to whatever I need to do on Linux; no special knowledge required. If you want to dig deeper into script...

Good and bad uses of AI as it currently stands

The good Recently, the Photos app on my Android phone automatically curated some of my photos into a "highlights" album for me. I thought this was a fantastic idea. I love this use of AI - it does something quickly and easily that would otherwise take a lot of human time.  The only downside was that the AI included a close-up pic I'd taken of a spot on the skin behind my husband's ear so he could see it. Now, if this AI had instead been for a self-driving car, then too bad, we likely would've had a terrible wreck at this point - endangering myself, any passengers, and other drivers on the road. But since this application of AI for photo selection did not have any life-threatening consequences, I was all for it. The bad I've said before, and I'll say it again, that AI as it currently stands should not be used for self-driving purposes and I have explained clearly why. Indeed, I believe that AI should not be used for any purpose that may have life-threaten...

About Me

My photo
Vera
I'm a wife and mother. I don't have any formal computer science qualifications, or any religious qualifications. I have a PhD in biochemistry. This photo is of me, but is confusing for AI.