# Use of "next" in Ruby 1.9?

**URL:** <https://www.ruby-forum.com/t/use-of-next-in-ruby-1-9/147250>\
**Category:** Ruby\
**Created:** [August 29, 2008, 8:38pm UTC](https://www.ruby-forum.com/t/use-of-next-in-ruby-1-9/147250 "2008-08-29T20:38:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Charles\_Turner](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/13edae/32.png) [@Charles\_Turner](https://www.ruby-forum.com/u/Charles_Turner)\
**Post date:** [August 29, 2008, 8:38pm UTC](https://www.ruby-forum.com/t/use-of-next-in-ruby-1-9/147250/1 "2008-08-29T20:38:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Charles\_Turner](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/13edae/32.png) [@Charles\_Turner](https://www.ruby-forum.com/u/Charles_Turner)\
**Post date:** [August 29, 2008, 10:33pm UTC](https://www.ruby-forum.com/t/use-of-next-in-ruby-1-9/147250/2 "2008-08-29T22:33:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Charles\_Turner](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/13edae/32.png) [@Charles\_Turner](https://www.ruby-forum.com/u/Charles_Turner)\
**Post date:** [August 29, 2008, 8:51pm UTC](https://www.ruby-forum.com/t/use-of-next-in-ruby-1-9/147250/3 "2008-08-29T20:51:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Charles\_Turner](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/13edae/32.png) [@Charles\_Turner](https://www.ruby-forum.com/u/Charles_Turner)\
**Post date:** [August 29, 2008, 10:53pm UTC](https://www.ruby-forum.com/t/use-of-next-in-ruby-1-9/147250/4 "2008-08-29T22:53:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Charles\_Turner](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/13edae/32.png) [@Charles\_Turner](https://www.ruby-forum.com/u/Charles_Turner)\
**Post date:** [August 30, 2008, 2:23am UTC](https://www.ruby-forum.com/t/use-of-next-in-ruby-1-9/147250/5 "2008-08-30T02:23:43Z")

</div>

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? 🙂

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

Best, Charles

---

<div class="post-metadata">

**Author:** ![Charles\_Turner](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/13edae/32.png) [@Charles\_Turner](https://www.ruby-forum.com/u/Charles_Turner)\
**Post date:** [August 30, 2008, 5:43am UTC](https://www.ruby-forum.com/t/use-of-next-in-ruby-1-9/147250/6 "2008-08-30T05:43:07Z")

</div>

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? 🙂
> 
> 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

---

<div class="post-metadata">

**Author:** ![Charles\_Turner](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/13edae/32.png) [@Charles\_Turner](https://www.ruby-forum.com/u/Charles_Turner)\
**Post date:** [August 30, 2008, 1:47pm UTC](https://www.ruby-forum.com/t/use-of-next-in-ruby-1-9/147250/7 "2008-08-30T13:47:19Z")

</div>

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
