Calling protected class method from instance method in Ruby

前端 未结 3 1041
粉色の甜心
粉色の甜心 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:59

    "The class method should be used inside the class scope, therefore should remain visible and callable within it, right?" Yes, that's correct, and that's the behavior Ruby exhibits. (As a point of clarification, instance scope is not "within" class scope. They are, appropriately, separate.)

    The non-send solution is to subclass or reopen the class to add a public class method to access the protected class method.

提交回复
热议问题