From: Robert Klemme Date: 2009-06-16T01:45:13+09:00 Subject: Re: confusion about object method scoping On 15.06.2009 18:31, Christopher Carver wrote: > Hello, > > I am defining a class. That class has several methods. In one of the > class methods I'm trying to use a previously defined method. It's > throwing an exception. Here's some code that demonstrates my problem. > Am I really unable to have a class use some of it's own methods if > they've already been defined? Thanks in advance! > > class Calculator > > private > def add(x,y) > x+y > end > > public > def Calculator.factorial(x) > result = 0 > > (1..x).each { |number| > result = add(result,number) > } > > result > end > > end > > puts Calculator.factorial() > You are mixing class and instance methods. You need to make add also a class method, e.g. by doing something like this class Calculator class <