From: matz@... (Yukihiro Matsumoto) Date: 2001-10-27T06:13:23+09:00 Subject: [ruby-talk:23533] Re: FileSpec vs Dir/File class methods Hi, In message "[ruby-talk:23427] FileSpec vs Dir/File class methods" on 01/10/26, Keith Hodges writes: |I would like to know whether there is a good reason for the current design of |the File and Dir classes that use class methods for most of their operations, |the only reason I can think of is that for some reason it is more economical to |use strings for filenames rather than have a class that instanciates potential |files. Yes. Strngs are strings. I believe there's good reason to separate strings and files in roles. |I always have this nagging feeling that I am doing too much work when handling |lists of files since Dir.entries returns a list of filenames that need to be |reunited with their directory path to be useful. Use 'find'. ;-) |Have a FileSpec, DirSpec, UrlSpec classes whose instances specify a potential |directory/file or url, whether it exists or not. ||'/usr/aDirectory'.fileSpec.exists? |'/usr/aDirectory'.fileSpec.directory? |'/usr/aDirectory'.fileSpec.fileEntries { | fileSpec | fileSpec.open { | file || file each { | line | puts line} } } |fs = '/usr/aDirectory/aFile'.fileSpec |fs.touch unless fs.exists? I'm not sure how useful they are than conterparts: File.exist?('/usr/aDirectory') File.directory?('/usr/aDirectory') Dir.foreach('/usr/aDirectory') {|fn| File.foreach('/usr/aDirectory/'+fn) {|line| puts line } } fn = '/usr/aDirectory/aFile' # oops, we don't have File.touch File.open(fn, "w").close unless File.exist?(fn) except for the fact (that you mentioned) that Dir.entries returns a list of filenames that need to be reunited with their directory path. Maybe it's enough to have a method returns full path of directory entries. matz.