From: Michael Selig Date: 2006-10-23T09:42:20+09:00 Subject: Re: String not enumerable, what about IO? ----- Original Message ----- From: "Sam Roberts" Sent: Saturday, October 21, 2006 3:33 AM > On Fri, Oct 20, 2006 at 01:24:29PM +0900, Michael Selig wrote: > > 1) There are several methods in Array which I think could (should?) also be > > in Enumerable (eg: uniq, +, | etc). > > > > 2) Presumably, as an alternative to most of the Enumerable methods, you > > could use "to_a", and then use Array methods. I guess the Enumerable methods > > would be more efficient than doing this, so is that the reason for using > > them, or is it brevity or something else? > > Probably not more efficient, you have to build an Array internally to > sort, for example. I guess my point was that there are multiple, similar ways of doing something, which may be confusing. Also that you really have to be cogniscent of the fact that the Enumerable methods call #each, so you have to think about efficiency, and whether a repeat call will even return the same things (eg: IO). Converting to an array is certainly simpler to understand IMHO, but is likely to be too inefficient in some circumstances (eg: a single-pass sequential read of a large file). "Lazy" array evaluation would certainly help. > > Array methods available (delete, insert etc). May be a new module, rather > > than polluting Enumerable? > > Maybe Arrayable? > > But remember that every method in Enumerable is implemented in terms of > the underlying #each. > > How would you define a #[]= method in Enumerable? What method would it > require the class to have? How would you even implement #[]= for a > file, IO, or Socket? Further down in my mail, I was suggesting that the base class provide #[] & optionally #[]=. Without the latter, "update" methods would fail. Treating a read/write disk file like an array is certainly feasible to implement. Sure there may be base classes for which some of the mix-in methods wouldn't be appropriate. Whether it's desirable to implement this is another question :-) Mike.