From: Kevin Smith Date: 2001-10-28T09:16:48+09:00 Subject: [ruby-talk:23655] Re: Path class (was: Re: FileSpec vs Dir/File class methods) --- Michael Witrant wrote: > You can find a first try there: > http://www.lepton.fr/ruby/path.rb Cool. > 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? 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? > - #/(other) > like #join(other) Not sure if I like this or if it scares me (or both). > A new method String#path converts a String to a Path. I would rather just do Path.new(string) than clutter up String itself. > - Should Path#delete call Dir.rmdir if the path is a > directory and File.delete otherwise? > For now it just calls File.delete. You must call > Path#rmdir to remove a directory. 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. > - Using this class instead of builtins adds at least one > extra call per > method. Maybe should it be converted to a faster C > module? For me, I'm already doing disk operations, so I'm not that concerned about speed. Having it in Ruby is nicer, I think. > - 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" > - Would a #rmtree method be nice? It would act like > #delete, but remove > the entire directory tree if it exists. Like 'rm -fr'. Yes. Dangerous, but extremely handy. > - Should it provide a way make all strings behave like a > Path? And how? No. Thanks for doing this! Nice work. Kevin __________________________________________________ Do You Yahoo!? Make a great connection at Yahoo! Personals. http://personals.yahoo.com