开发者

How to set just one method to private in Ruby?

I have a class with N methods. I want to set one of these methods to private. How can I do 开发者_如何学运维this?


 class Example
    def methodA
    end

    def methodP
    end

    private :methodP
  end


I like this way:

class Example
    def public_method1
    end

    private def used_by_public_method1
    end

    def public_method2
    end
end

Another option (that I find more confusing):

class Example
    def public_method1
    end

    def public_method2
    end

    private

    def used_by_public_method1
    end

    # Don't accidentally put public methods down here.
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜