From: Trans Date: 2008-08-19T15:19:49+09:00 Subject: Fools Filing Ya know, it always seems like I'm jump'n all around with these file/ dir related classes/modules/methods. We have: * File * Dir * FileTest * FileUtils * Pathname Not to mention the String we often use to store the filename. It seems so hap hazard and the code is more often than not looking distinctly non-OOP. While using pathname helps, it doesn't seem to quite cut it, and I end falling back to File or Dir here and there. So I came upon and particular case that got me thinking what the fundamental problem might be. I had extended Pathname with #glob basically like so: def glob(pattern, opts=0) Dir.glob(self + pattern, opts).collect{ |f| Pathname.new(f) } end Works great. But then I went to do: somepathname.mkdir('foo') And it bombed. Why? Because it doesn't expect a path argument, but rather it wants to make the directory indicated by the pathname object itself. So the two method don't mesh well. You might think that my glob definition is the one out of sync, but if you define glob to act on the pathname itself, eg. Pathname.new('*').glob, code starts to get ugly again. Compare: (Pathname.new('foo') + '*').glob Pathname.new('foo').glob('*') My immediate thought was then, what about Dir, does it support #glob? That was immediately followed by, "hey, I never ever use Dir.new". That was key. I looked it up: Instance Methods: close, each, path, pos, pos=, read, rewind, seek, tell That's it. I don't even fully understand what all those do. It's treating a Dir as an IO object? And there's the problem, what we need are "lazy" File and Dir classes that delegate to the IO ones, that allow us to do everything we need, rather than fussing with all these others. I think I'll throw this together. Anyone else interested? T.