--90e6ba2121d7fef16f04a976ef01 Content-Type: text/plain; charset=UTF-8 On Mon, Aug 1, 2011 at 8:33 PM, Marc Chanliau <marc.chanliau / gmail.com>wrote: > class Factorial > def fact(n) > if n 0 > 1 > else > n * fact(n-1) > end > end > end > > my_fact actorial.new > puts "enter a positive integer: " > my_fact ets.to_i > puts "factorial: #{fact(n)}" > You're relying on `n` being defined here, but it's only defined inside Factorial#fact, which is why you get "undefined local variable or method `n'" as an error message. You probably wanted to do this: puts "factorial: #{fact(my_fact)}" As a perhaps neater way of writing the #fact method, I'd do it like this (although it's moot, really): def fact(n) return 1 if n 0 n * fact(n-1) end --90e6ba2121d7fef16f04a976ef01--