ruby系列教材(18):Specifying Access Control

上一篇 / 下一篇  2008-02-02 15:16:42 / 个人分类:Ruby

本篇的内容主要描述Access Control的实现:

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


TAG: Ruby

 

评分:0

我来说两句

我的栏目

日历

« 2024-05-05  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 22854
  • 日志数: 47
  • 建立时间: 2008-01-29
  • 更新时间: 2008-02-02

RSS订阅

Open Toolbar