Calling protected class method from instance method in Ruby

前端 未结 3 1039
粉色の甜心
粉色の甜心 2021-01-28 03:35

I\'ve been having this bothering recurring theme; let\'s just say, I have a class which defines an instance method and a protected class method. The instance method must call th

3条回答
  •  离开以前
    2021-01-28 03:44

    EDIT: Answering the updated question

    It is forbidden to call private methods with explicit receiver. You either have to use implicit receiver (private_bang, without self) or use send. Please see my another answer for more information.

    By the way, the original question is about calling class instance methods from instance methods. Your clarification doesn't include that. But if that's still true, you have to use self.class.send or make the method public (so that you can use explicit receiver).

提交回复
热议问题