Hi --

On Fri, 20 Oct 2006, Nikolai Weibull wrote:

> On 10/19/06, dblack / wobblini.net <dblack / wobblini.net> wrote:
>
>> On Thu, 19 Oct 2006, Nikolai Weibull wrote:
>
>> > Anyway, I'd love to be able to write
>> >
>> > IO.read(file).lines.each{ |line| puts line if line =~ pattern }.
>
>> If lines were a collection of lines, you could do exactly that.  And,
>> just to say it again, I'm not saying that there should be no methods
>> that return Enumerators, just that "things" sounds (to my Ruby-trained
>> mind :-) like a collection/array of things.
>
> But it /is/ a collection of lines.  And it works just fine without an
> intermediate array.  What I'm saying is that you may have to retrain
> your mind to get it to understand that a collection can be represented
> by other things than a plain-ol' array.

Let me rephrase my point, then: When I say "things", I expect a
plain-ol' array :-)  Or something like it.  I don't like this:

   irb(main):004:0> str.lines[0]
   NoMethodError: undefined method `[]' for
    #<Enumerable::Enumerator:0xb5f6ebf8>

I'd rather see lines return an array, and some other method return an
Enumerator.  Arrays may be old-fashioned, and appeal chiefly to the
untrained mind :-)  But they're a better fit for a "things"-style
method call.


David

-- 
                   David A. Black | dblack / wobblini.net
Author of "Ruby for Rails"   [1] | Ruby/Rails training & consultancy [3]
DABlog (DAB's Weblog)        [2] | Co-director, Ruby Central, Inc.   [4]
[1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com
[2] http://dablog.rubypal.com    | [4] http://www.rubycentral.org