When is File.join useful?

后端 未结 2 1920
面向向阳花
面向向阳花 2021-02-12 01:22

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(\'/\')<

相关标签:
2条回答
  • 2021-02-12 02:03

    It will use File::SEPARATOR, which in theory need not be /.

    0 讨论(0)
  • 2021-02-12 02:14

    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"
    
    0 讨论(0)
提交回复
热议问题