Point well taken - though, at the risk of beating a dead wildebeast here, what I'd begun to wonder about after posting the first message was a consistent default-semantic for instance method names when invoked as class methods: "if no class method by that name exists, operate on a new instance constructed with the given argument(s), if any" -- isn't it true that where we do have duplicate class methods, this is what we generally expect to happen anyway? Hmm. Adding unnecessary methods is, I agree, clumsy, but as a language feature this could only have the reverse effect, shrinking the standard libraries a bit by rendering the existing duplicate class methods unnecessary except in the cases where they need to deviate from that behavior. The question to me then becomes whether it costs anything in exchange for what it buys, perhaps in terms of performance. On the other hand maybe this kind of thing strays a bit too far into the realm of "Do what I mean", and yes it diverges from OOP conventions. It was just a strange and fun thought that occurred to me. And yes, in this particular case, the "File.open(name).read" formulation seems quite straightforward and elegant. Mark Yukihiro Matsumoto wrote: > Hi, > > In message "[ruby-talk:4608] Class methods" > on 00/08/28, Mark Slagell <ms / iastate.edu> writes: > > |Reading the thread about regexp matches made me wonder about this: > | > | def File.read(s) > | File.new(s).read(nil) > | end > | > |Then File.new("filename").read(nil) could be written more simply and > |readably as File.read("filename") -- rather like "atime" is implemented > |both as a class method and an instance method. Are there reasons not to > |do such things? (more methods => performance suffers, perhaps?) > > Well, I don't want to provide every method of IO/File as a class > method like readlines/mtime. It's too clumsy. I'd like to provide > useful ones. I felt that the method to open file and read a leading > fixed sized content from it, then close the file, is not quite useful. > > But IO#read provides the feature to read whole content too. Now, I > feel the class method to read whole content may be useful. Although, > > File::open(s).read > > will do the job (unclosed file will be closed by GC). > > matz.