1. 首页
  2. 数据库
  3. 其它
  4. Ruby 之 class 中的 private、 protected、public

Ruby 之 class 中的 private、 protected、public

上传者: 2021-01-31 01:30:16上传 PDF文件 28.98KB 热度 16次
Private private 函数只能 在本类和子类的 上下文中调用,且只能通过self访问。 这个意思就是:private函数,只能在本对象内部访问到。 对象实例变量(@)的访问权限就是 private。 代码如下: class AccessTest def test return “test private” end def test_other(other) “other object ”+ other.test end end t1 = AccessTest.new t2 = AccessTest.new p t1.test # => test private p t1.test_
下载地址
用户评论