From: Daniel Roux Date: 2009-06-16T01:40:39+09:00 Subject: Re: confusion about object method scoping --0016e6471b0ac4c1b0046c65b7f3 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On Mon, Jun 15, 2009 at 11:31 AM, 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 Is it? ArgumentError: wrong number of arguments (0 for 1) You're calling your method without a required argument. > > puts Calculator.factorial() > > Which you defined when you wrote: def Calculator.factorial(x) You could send a default value if you don't want to specify one everytime def Calculator.factorial(x = 0) -- Daniel Roux --0016e6471b0ac4c1b0046c65b7f3--