Every gist with this icon (
Every repository with this icon (
Filename class
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|





