From reading the documentation, it's apparent that File.join joins the given parameters with the / character.
When is using this, as opposed to filenames.join('/')
, beneficial?
There is another, subtle difference:
File.join('foo','bar') #=> "foo/bar" ['foo','bar'].join('/') #=> "foo/bar"
But, if you pass an argument already ending with /
(which is quite often when working with paths), you won't have two slashes in the result:
File.join('foo/','bar') #=> "foo/bar" ['foo/','bar'].join('/') #=> "foo//bar"
It will use File::SEPARATOR
, which in theory need not be /
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With