On Sat, Nov 16, 2002 at 06:07:50AM +0900, dblack / candle.superlink.net wrote:
> Yes, that's the very behavior that raises the question (to the extent
> that it is a question) about the presence/absence of the block
> affecting the return value of the method.  Which for some reason seems
> anomalous to me....  I'm still not entirely sure why.  I have to do
> some digging and refresh my memory as to how blocks with optional
> methods usually behave.  

Did you mean methods with optional blocks?

FWIW, this is how the #scan method in my Archive::Reader::XYZ classes
behaves:

    io = File.open('archive.ar')
    reader = Archive::Reader::Ar.new(io)

    # block provided; method returns nothing

    reader.scan do |entry|
      do_something_with(entry)
    end

    # no block; method returns an Enumerable of entries

    entries = reader.scan

This way, when you just want sequential access once (e.g. for
extracting all entries), #scan doesn't build an extra object.  If you
want to access it randomly or more than once, you don't pass a block
and it builds and returns the Enumerable.


Massimiliano