Array#rotate fails in a simple program

I’m runing Ruby 1.8.6 over WinXP-Pro/SP3

I’m writing a program to illustrate prime numbers and Ruby programming
for my teenage granddaughter. Unfortunately, I’ve got a problem:

On line 54, I’ve got the statement:
$primes.rotate!(group_size)

That results in the error:
Adrienne01.rb:54: undefined method `rotate!’ for [2, 3, 5, 7]:Array
(NoMethodError)

However, RDoc Documentation defines “ary.rotate!(cnt=1) →
ary”
Also, “rotate” (without the bang) is defined in Ruby/core and fails in
the same manner.

I’ve posted the program and its output in http://www.pastie.org/1674687

Is Array#rotate! only defined in a Ruby version later than mine? Or
is there something I’m missing here?

Any guidance offered will be gratefully received.

Best wishes,
Richard

Is Array#rotate! only defined in a Ruby version later than mine? Or
is there something I’m missing here?

Yes. The ruby-doc.org link is for Ruby 1.9.2. (Also, 1.8.6 is a rather
old version of Ruby, so you might want to consider upgrading anyway
even if you’re not impacted by the loss of #rotate!).

~ jf

John F.
Principal Consultant, BitsBuilder
LI: http://www.linkedin.com/in/johnxf
SO: User John Feminella - Stack Overflow

On Tue, Mar 15, 2011 at 11:23, RichardOnRails

On Mar 15, 11:31am, John F. [email protected] wrote:

Principal Consultant, BitsBuilder

the same manner.

Thanks John: Point taken! I’m installing 1.9.2, plus Pik for switching
(in a Windows environment) between Ruby versions and Rails versions.

Best wishes,
Richard

If upgrading isn’t an option you could use each_slice from the
enumerator
stdlib.

require ‘enumerator’

[2,3,5,7,11,13,17].each_slice(2) do |pair|
puts pair.join(‘,’)
end

#output
2,3
5,7
11,13
17

2011/3/15 RichardOnRails [email protected]