From: Yossef Mendelssohn Date: 2007-08-29T23:05:08+09:00 Subject: Re: array.sort On Aug 29, 8:39 am, Mark Ransom wrote: > Hi, > > I'm a novice programmer who is just starting out in Ruby. I've been > playing around with arrays and have run into a problem: > > This works: > > array = [3,2,1] > puts array.sort > > =>123 > > BUT this doesn't (error attached): > > nums = Array.new > > numplays = 5 > > numplays.times do > > for values in 1..5 > ball = rand(56) > redo if ball == 0 || nums.include?(ball) > nums [values] = ball > end > puts nums.sort > end > > Can anyone shed light on this newby? > > Attachments:http://www.ruby-forum.com/attachment/183/array_sort.JPG > > -- > Posted viahttp://www.ruby-forum.com/. Ah, Stefano got to it before me, but here's a reworking of it anyway: numplays = 5 numballs = 5 numplays.times do nums = Array.new numballs.times do ball = rand(55) + 1 redo if nums.include?(ball) nums.push ball end puts 'nums' puts nums.sort end -- -yossef