From: Michael Witrant Date: 2001-10-29T05:10:43+09:00 Subject: [ruby-talk:23693] Re: Path class (was: Re: FileSpec vs Dir/File class methods) On Sun, 28 Oct 2001 09:16:48 +0900, Kevin Smith wrote: > > The Path class inherits from String and implements: > > I'm curious why you chose to extend String, rather than > just contain a String. Do you really want/expect to be able > to perform every String operation on a Path object? Not anymore. The next version won't inherits from String and, as suggested by Matz, implement #to_str. It will also provide some String methods (like +, ==, empty?, gsub[!], ...) > What if you're on a Mac, where (as I probably misunderstand > it), it's difficult to represent an entire pathspec in a > single string? > I don't know anything about Mac. How do their paths differ? > > - #/(other) > > like #join(other) > > Not sure if I like this or if it scares me (or both). I personally like it. There is mainly two type of concatenation of paths: adding a string at the end of the last entry, and adding a subname. I don't think I use the first one more, so an operator for the second one sounds good for me. The '/' operator is never used except in Numerics and I don't think someone will come with a nice generic '/' behavior that might apply to many classes and make Path's one disturbing. (ROOT / 'bin' / binary) looks better than ("#{ROOT}/bin/#{binary}") or (ROOT.join 'bin', binary) for me. > > A new method String#path converts a String to a Path. > > I would rather just do Path.new(string) than clutter up > String itself. I'm going to remove String#path. Path[str] will also be availiable. > Perhaps you could have: > #delete (deletes files, no effect for directories) > #rmdir (deletes directories, no effect on files) > #delete! (deletes file OR directory) > > I can't think of a better name than #delete! but there > probably is one. #delete! makes me think that it will try everything availiable to ensure the path is removed. It sound good, and might even replace #rmtree. > > - Should #join (and #/) remove duplicate slashes? > > ie: '/bar/'.path.join('foo') => '/bar//foo' or > > '/bar/foo'? > > File::join does not. > > Wow. I would have thought that would be the main reason > join would exist. Yes, I think it should remove duplicate > slashes (except if it handles things like > "file://c:/config.sys" or "\\MyWinBox\MyShare\file" So maybe should it only check for slashes at the end of the path and at the beginning of the subpath. For example 'a' / 'b', 'a/' / 'b', 'a' / '/b' and 'a/' / '/b' would all return 'a/b', but '//a/' / 'b' would give '//a/b' As I wrote these replies, I worked on version 0.2.0. It's availiable there: http://www.lepton.fr/ruby/path As soon as I write some documentation, I post it on the RAA. Mike.