From: Daniel Brumbaugh Keeney Date: 2008-02-20T09:25:04+09:00 Subject: Re: Is there any object-oriented File class in ruby ? On Feb 19, 2008 4:45 PM, tom_33 wrote: > For example, the class File seems to have a big bunch of procedural > functions (or static methods, or whatever you want to call them) that > needs the filename to be provided as a parameter. > > For example, the ruby method File.basename is documented as only > supporting forward slashes, regardless of the local file system. > File.basename("/home/gumby/work/ruby.rb") #=> "ruby.rb" > Essentially, this seems to be not much more than a string parsing > function with no OO abstraction that represents a file object. > Compare this with doing the same thing with java: > File f = new File("/home/gumby/work/ruby.rb"); // or new File("C:\\home > \\gumby\\work\\ruby.rb"); > f.getName() #=> "ruby.rb" > > Now my question is what have I been missing here ? > I mean, is there any other much better File class somewhere in the > Ruby core that is more pure OO, or otherwise why is a language with a > CORE procedural "class" library described as being a pure oo > language ? > > / Tom I too once thought exactly as you do. I still think it would probably be best if File didn't have all those class methods. In reality, I think what you're looking for is the Pathname class. In my mind, a Pathname is a file reference, it has all the appropriate methods of a file like mtime or directory?. A File, on the other hand, is an IO stream. An IO stream has no concept of mtime or basename, it is for reading and writing, and has no business with such methods. The real shame in my mind is that File.new doesn't accept a pathname as a first parameter, only a string. Daniel Brumbaugh Keeney