Pathname has an #mkdir method to create a directory at the path, but does not have a #touch method to create an empty file at that path.
There were numerous cases where I had to fallback to using
new_file = Pathname.new('location/for/new/file')
instead of simply being able to use:
I would like to add this method. If you like it, let me know. I will provide a patch then.
#6 [ruby-core:76451] Updated by Naja Melan 6 months ago
I prefer something like (warning, untested code):
def touch( subPath = '', **options ) path = @path ret = self if directory? ret = join subPath path = ret.to_path end FileUtils.touch( path, **options ) ret end
lets you do:
I think touch is a good name because everybody already knows it and it's what people will try out spontaneously before even looking in the docs why it doesn't work. Joel Spolsky explains quite well why this is a good thing.
#7 [ruby-core:76455] Updated by Shyouhei Urabe 6 months ago
We don't always blindly import broken designs; for instance Ruby do not have creat(2) equivalent method. "Everybody knows it" is (definitely a good property but) not enough.
When it comes to touch, there already is
FileUtils.touch so your urgent needs are already satisfied I believe. Here on
Pathname let us consider a clearer design.