C
Christopher Carver
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()
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()