From: "Mayank K." Date: 2011-03-23T18:57:43+09:00 Subject: Nil can't be coerced into Fixnum (TypeError) I am trying to execute the following code and it seems like the array is going out of bounds. Let me know where am I going wrong. class PrimeFactor def initialize(number) @number = number end def primeFactors factors = Array.new (2..Math.sqrt(@number).ceil).each do |num| if ( @number % num == 0 ) factors.insert(factors.length,num) end end (0...factors.length).each do |i| prime = factors[i] factors = factors.select { |x| x == prime || x % prime !=0 } end factors.compact.join(',') end end prime = PrimeFactor.new(13195) puts "#{prime.primeFactors}" C:\Temp\Study\Ruby>ruby --version ruby 1.8.7 (2011-02-18 patchlevel 334) [i386-mingw32] C:\Temp\Study\Ruby>ruby prime.rb prime.rb:16:in `%': nil can't be coerced into Fixnum (TypeError) from prime.rb:16:in `primeFactors' from prime.rb:16:in `select' from prime.rb:16:in `primeFactors' from prime.rb:14:in `each' from prime.rb:14:in `primeFactors' from prime.rb:24 -- Posted via http://www.ruby-forum.com/.