Cycle in Ruby 1.9?

Hi all-

I’ve seen a number of references to being able to pass an argument to
cycle() to limit its behavior to a finite number of iterations.
However, I get this in irb 1.9.0:

ruby 1.9.0 (2007-12-25 revision 14709) [i686-darwin9.4.0]
spinoza:~$ irb
irb(main):001:0> (‘a’…‘c’).cycle(2)
ArgumentError: wrong number of arguments(1 for 0)
from (irb):1:in cycle' from (irb):1 from /usr/local/lib/ruby/1.9.0/irb.rb:150:inblock (2 levels) in
eval_input’
from /usr/local/lib/ruby/1.9.0/irb.rb:259:in signal_status' from /usr/local/lib/ruby/1.9.0/irb.rb:147:inblock in eval_input’
from /usr/local/lib/ruby/1.9.0/irb.rb:146:in eval_input' from /usr/local/lib/ruby/1.9.0/irb.rb:70:inblock in start’
from /usr/local/lib/ruby/1.9.0/irb.rb:69:in catch' from /usr/local/lib/ruby/1.9.0/irb.rb:69:instart’
from /usr/local/bin/irb:13:in `’
irb(main):002:0>

Any thoughts on why this doesn’t work for me?

Best, Charles

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

I’ve seen a number of references to being able to pass an argument to
cycle() to limit its behavior to a finite number of iterations.
However, I get this in irb 1.9.0:

ruby 1.9.0 (2007-12-25 revision 14709) [i686-darwin9.4.0]
spinoza:~$ irb
irb(main):001:0> (‘a’…‘c’).cycle(2)
ArgumentError: wrong number of arguments(1 for 0)

Ruby 1.9 has changed a lot since Christmas. Here’s the same code
running on a build based on today’s HEAD:

dave[RUBY3/Book 18:41:43*] ruby -ve “p((‘a’…‘c’).cycle(2))”
ruby 1.9.0 (2008-08-30 revision 15427) [i386-darwin9.4.0]
#Enumerator:0x0d85cc

Expanding the Enumerator gives

dave[RUBY3/Book 18:41:49*] ruby -ve “p((‘a’…‘c’).cycle(2).to_a)”
ruby 1.9.0 (2008-08-30 revision 15427) [i386-darwin9.4.0]
[“a”, “b”, “c”, “a”, “b”, “c”]

Cheers

Dave