Ruby定义私有方法的两种途径

#定义私有方法途径1:
class C
    def public_method
        private_method
    end

    def private_method  
    end

    private :private_method  #定义方法为私有
end

#定义私有方法途径2:
class C
    def public_method
        private_method
    end

    private
    def private_method  #定义私有方法
    end
end

C.new.public_method

 

posted on 2013-12-29 13:28  秋叶leaf  阅读(248)  评论(0)    收藏  举报