On Thu, Oct 19, 2006 at 08:16:54PM +0900, dblack / wobblini.net wrote:
> On Thu, 19 Oct 2006, Jim Weirich wrote:
> >Rick DeNatale wrote:
> >>On the other hand, I too tend to think that lines (without a block)
> >>really should return an array of lines, and chars and bytes should
> >>follow suit.
> >
> >I think I disagree.  If lines without a block returns an array, then using 
> >inject, collect, or any other enumerable method applied line by line would 
> >always work on an intermediate array.  That seems like unnecessary 
> >overhead.
> 
> There are two separate questions involved, though:
> 
>   1. Should there be a method to enumerate over the lines without
>      creating an intermediate array?
>   2. Should that method be called "lines"?

What about: 
* defining String#to_enum, which would accept an argument (:lines, :chars or
  :bytes) defaulting to :lines. Note that right now (in HEAD) "foo".to_enum
  ends up using Kernel#to_enum, raising a NameError (undefined #each for class
  String).
* making  str.lines (chars, bytes) equivalent to  
  str.to_enum(:lines).to_a  (respectively :chars, :bytes)
?

This way one would do
  string.to_enum.inject{ ... }
where we currently have
  string.lines.inject{ ... }

string.to_enum(:chars).max is longer than
string.chars.max,  but the reciprocal operation would look better:
string.chars vs. string.chars.to_a

-- 
Mauricio Fernandez  -   http://eigenclass.org   -  singular Ruby