Ruby定义私有方法(private)的两种办法
- 作者: 喜欢试衣间
- 来源: 51数据库
- 2021-08-20
#定义私有方法途径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
推荐阅读
