[#4567] Re: What's the biggest Ruby development? — Aleksi Niemel<aleksi.niemela@...>

Dave said:

18 messages 2000/08/23
[#4568] Q's on Marshal — Robert Feldt <feldt@...> 2000/08/23

[#4580] RubyUnit testcase run for different init params? — Robert Feldt <feldt@...> 2000/08/25

[#4584] Re: RubyUnit testcase run for different init params? — Dave Thomas <Dave@...> 2000/08/25

Robert Feldt <feldt@ce.chalmers.se> writes:

[#4623] Re: RubyUnit testcase run for different init params? — Robert Feldt <feldt@...> 2000/08/28

On Sat, 26 Aug 2000, Dave Thomas wrote:

[#4652] Andy and Dave's European Tour 2000 — Dave Thomas <Dave@...>

24 messages 2000/08/30
[#4653] Re: Andy and Dave's European Tour 2000 — matz@... (Yukihiro Matsumoto) 2000/08/30

Hi,

[#4657] Ruby tutorials for newbie — Kevin Liang <kevin@...> 2000/08/30

Hi,

[ruby-talk:4630] Re: Class methods

From: Mark Slagell <ms@...>
Date: 2000-08-29 04:08:31 UTC
List: ruby-talk #4630
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.


In This Thread