0

I have a class method, self.calculate, that I want to invoke from both another class method and from an instance method.

If I write

def green
  calculate(x,y,z)
end

though, I get a NoMethodError: undefined method 'calculate' exception. Invoking self.calculate gets the same problem.

What does work is calling MyClassName.calculate, but that seems somehow wrong and messy. What is the correct practice in this situation?

1
  • Umm ... MyClassName.calculate should not work if calculate is private as you claim. Commented Apr 10, 2015 at 7:16

1 Answer 1

2

You can use

self.class.calculate

to call a class methods from an instance method.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.