Daniel Roux
6/15/2009 4:41:00 PM
[Note: parts of this message were removed to make it a legal post.]
On Mon, Jun 15, 2009 at 11:31 AM, Christopher Carver <ccarver0@gmail.com>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