Use of "next" in Ruby 1.9?

Hi all-

Fiddling around with external iterators in Ruby 1.9,
and had a question. Given the following method definition:

def twice
if block_given?
yield 1
yield 2
else
self.to_enum(:twice)
end
end

Why does:

iter = twice
puts iter.next

display output, but:

iter = twice
iter.next {|x| puts x }

doesn’t?

Best, Charles Turner

On Sat, 30 Aug 2008 03:41:08 +0900, Dave T. wrote:

next() doesn’t take a block.

Thanks. That tidbit seems like an omission from Flanagan’s book,
although I suppose it’s not easy to track everything going on with 1.9.

Would that make next() the only enumerable() that doesn’t take a block?

Best, Charles

On Aug 29, 2008, at 1:33 PM, Charles Turner wrote:

puts iter.next

display output, but:

iter = twice
iter.next {|x| puts x }

doesn’t?

next() doesn’t take a block.

Dave

On Aug 29, 2008, at 2:56 PM, Charles Turner wrote:

next() doesn’t take a block.

Thanks. That tidbit seems like an omission from Flanagan’s book,
although I suppose it’s not easy to track everything going on with
1.9.

Ahh… that’s why you need the 3rd edition PickAxe–
I’ve been tracking all the 1.9 changes. I just added the descriptions
of 19 new methods added in the last 4 days, including the curiously
useful each_with_object. (The next beta containing these changes
hasn’t been released yet—I’m still working on the section describing
the new trust mechanism).

All in all, over two hundred methods have been added to 1.9 since the
start of the year.

Would that make next() the only enumerable() that doesn’t take a
block?

Methods such as #first and #take don’t take a block either.

Dave

On Sat, 30 Aug 2008 05:48:07 +0900, Dave T. wrote:

Ahh… that’s why you need the 3rd edition
PickAxe–I’ve been tracking all the 1.9 changes. I just added the
descriptions of 19 new methods added in the last 4 days, including
the curiously useful each_with_object. (The next beta containing
these changes hasn’t been released yete$B!=e(BI’m still working on the
section describing the new trust mechanism).

All in all, over two hundred methods have been added to 1.9 since the
start of the year.

Hi Dave-

I take it, then, that the book won’t be out on 9/15? :slight_smile:

Do you plan on continuing to update the PDF after the book goes to
press?

Best, Charles

On Aug 29, 2008, at 6:45 PM, Charles Turner wrote:

I take it, then, that the book won’t be out on 9/15? :slight_smile:

Do you plan on continuing to update the PDF after the book goes to
press?

Matz has announced a feature freeze in September: I’ll be seeing him
next week at the Lonestar Ruby Conference and I’ll kow more after
that, but I hope to finalize it at the same time 1.9 is frozen.

Dave

On Sat, 30 Aug 2008 12:37:26 +0900, Dave T. wrote:

Matz has announced a feature freeze in September: I’ll be seeing him
next week at the Lonestar Ruby Conference and I’ll kow more after
that, but I hope to finalize it at the same time 1.9 is frozen.

Actually the PDF is pretty nice: no need to wait, searchable, and 1000
pages less on my bookshelf.

Thanks, Charles