On 10/16/06, Sam Roberts <sroberts / uniserve.com> wrote:


> Btw, I'm assuming that #lines returns an Enumerable, not an Array,
> because exploding a string into an Array of all its constituent lines
> in-memory at once would be kindof heavy.

It actually returns an Enumerable::Enumerator.
$ irb1.9
irb(main):001:0> "abc\ndef".lines
=> #<Enumerable::Enumerator:0xb7cf1f04>

Note that in 1.9 the Enumerator module is part of the core and doesn't
need to be required.

One little quirk I just noticed is that String#lines seems to ignore a
block argument.
irb(main):002:0> "abc\ndef".lines {|l| puts l}
=> #<Enumerable::Enumerator:0xb7cec20c>

This is at odds with what the various each methods do:
irb(main):003:0> (1..3).each
=> #<Enumerable::Enumerator:0xb7ce39e0>
irb(main):004:0> (1..3).each {|num| puts num}
1
2
3
=> 1..3

This is as of the latest 1.9 I've got installed:
$ irb1.9 -v
irb 0.9.5(05/04/13)
$ ruby1.9 -v
ruby 1.9.0 (2006-10-08) [i686-linux]

I don't know if this has changed in the past week or so.




-- 
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

IPMS/USA Region 12 Coordinator
http://ipmsr12.denhaven2.com/

Visit the Project Mercury Wiki Site
http://www.mercuryspacecraft.com/