Forum: Ruby-core File.join is always forward slash?

947c97a2c119e85989d2ca63135a5b5e?d=identicon&s=25 Roger Pack (Guest)
on 2010-03-29 21:33
(Received via mailing list)
I've noticed this in windows:

>> File.join('a', 'b')
=> "a/b"

Which brings up this question in my mind...if it is always a forward
slash (on windows and Linux), then why does File.join exist (since its
purpose is to join paths in a platform dependent way, but it appears
to always just do it one way)?
Just some feedback on it.  It confuses more than just myself.
Thanks.
-rp
86c07aa43c6df798df005edd84ee8b56?d=identicon&s=25 Marc-Andre Lafortune (Guest)
on 2010-03-29 21:40
(Received via mailing list)
Hi,

Not sure if this answers your question, but:

    File.join('a', 'b') ==  File.join('a/', 'b') ==  File.join('a/',
'/b')

It will also convert non-strings to paths (with "to_path", ...)
8cbb39dadafaf2287a83a13ee4981ec9?d=identicon&s=25 U.Nakamura (Guest)
on 2010-03-30 11:31
(Received via mailing list)
Hello,

In message "[ruby-core:29115] File.join is always forward slash?"
    on Mar.30,2010 04:33:24, <rogerdpack2@gmail.com> wrote:
> I've noticed this in windows:
>
> >> File.join('a', 'b')
> => "a/b"
>
> Which brings up this question in my mind...if it is always a forward
> slash (on windows and Linux), then why does File.join exist (since its
> purpose is to join paths in a platform dependent way, but it appears
> to always just do it one way)?

It might be sure to be to use the slash.

As you know, the interal expression of the path separator in
ruby is always slash.
And, the external world might be not so. (Windows, old Mac OS,
VAX, etc...)
Therefore, to force using the internal expression in ruby at
the script level, File.join is being offered.

Regards,
This topic is locked and can not be replied to.