`
zhoujiabin810812
  • 浏览: 25462 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

ruby public protected private

阅读更多
class Person   
  def speak
    "protected:speak  "
  end 
 
  def laugh
    "   private:laugh"  
  end
 
  protected :speak
  private   :laugh
 
  def useLaugh(another)   
    puts another.laugh
  end 
 
  def useSpeak(another)  
    puts another.speak
  end 
 
end

p1=Person.new
p2=Person.new

p2.useSpeak(p1)
#p2.useLaugh(p1)
当p2.useLaugh(p1)执行的时候将会报错。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics