From: kwatch Date: 2008-09-15T22:07:56+09:00 Subject: Re: Q: IO.read() and IO.write() Thank you for everyone who replied me. On 2008/9/5 Robert Klemme wrote: > > > IMO, File.read() is more natural than IO.read() because > > IO class is not related to filename, I think. > > You can as well use File.read(). I know it. My question is that File.read() is more natural than IO.read() because filename is related with File, not IO. > > Why don't you just create a library of things you regularly need and > require that? It is one solution, but not answer for my question. > > > It is easy to define File.write() but I hope it is provided by Ruby. > > Probably because writing is more dangerous and also there are more > options to file writing than to read (beginning vs. at end, create or > not, text vs. binary). Your points apply to IO.read() as well as IO.write(). IO.read() is provided in default regardless it doesn't support binary mode. Don't get me wrong. I have just question, not blame. On 2008/9/15 Brian Candler wrote: > > I have to define File.write() for each project... > > Do you mean you want: > > File.write(filename, string) > > to overwrite the contents of the named file with the contents of the > string? Yes. > I'd just do > > File.open(filename,"w") { |f| f << string } > > It's not much more typing. If you use it lots, then as you say, you can > write your own method to do it. Yes, it is not so long, but IO.read(filename) is provided in spite that IO.open(filename) {|f| f.read } is also short. It is odd for me that IO.read() is provided and IO.write() is not. This is asymmetric. -- regards, makoto kuwata