Here’s the translation of the Go code example to Ruby, formatted in Markdown suitable for Hugo:
The File::Separator constant and File.join method in Ruby provide functionality to work with file paths in a way that is portable between operating systems; dir/file on Linux vs. dir\file on Windows, for example.
To run the program:
In this Ruby version:
We use File.join instead of filepath.Join to construct paths.
File.dirname and File.basename are used instead of filepath.Dir and filepath.Base.
File.absolute_path? is used to check if a path is absolute.
File.extname is used to get the file extension.
File.basename(filename, ext) is used to get the filename without the extension.
Pathname#relative_path_from is used to find the relative path between two paths.
Note that Ruby’s path handling is generally more straightforward and doesn’t require a separate package like Go’s filepath. Most of the functionality is available directly in the File and Pathname classes.