There is likely a way to do what I’m about to blog about, but I thought this might be useful in case there isn’t. Basically, I want a File object, but without the necessity of it actually being a file on the filesystem. For example, I’d kind of like to call "/tmp/myfile.txt".dirname and get "/tmp" back.
Ruby’s File class does not allow the following, unless /tmp/myfile.txt actually exists:
f = File.new("/tmp/myfile.txt")
And what’s worse (imo), you can’t do this once you have the file handle:
f.dirname
But it does allow this:
File.dirname("/tmp/myfile.txt")
When you have a lot of this kind of thing going on (getting dirname, basename, extname, etc.) it gets tiresome to type “File” all over the place. What we really need is a Filename object. And it should proxy methods to the File.* class methods.
Readme taken from original blog post