本篇的內容主要描述Access Control的實(shí)現:
1)方式一
class MyClass
def method1 # default is ‘public‘
#...
end
protected # subsequent methods will be ‘protected‘
def method2 # will be ‘protected‘
#...
end
private # subsequent methods will be ‘private‘
def method3 # will be ‘private‘
#...
end
public # subsequent methods will be ‘public‘
def method4 # and this will be ‘public‘
#...
end
end
2)方式二
class MyClass
def method1
end
# ... and so on
public :method1, :method4
protected :method2
private :method3
end
*在public 等后面加上Symbol literals
聯(lián)系客服