自己销毁自己的方法。
发表于:2006年07月14日  分类:Ruby  添加评论  1,569 次浏览 
http://redhanded.hobix.com/inspect/methodsThatSelfDestruct.html
  1.  
  2.  class Trial
  3.     def run_me
  4.        def self.run_me; raise Exception, "NO MORE." end
  5.        puts "Your trial period has ended." 
  6.     end
  7.  end
  8.  
  9.  t = Trial.new
  10.  t.run_me
  11.  #=> Your trial period has ended.
  12.  t.run_me
  13.  #=> (trial):3:in `run_me': NO MORE. (Exception)
好像只是只能调用一次而已,对于一个对象。
固定链接: http://liubin.nanshapo.com/2006/07/14/%e8%87%aa%e5%b7%b1%e9%94%80%e6%af%81%e8%87%aa%e5%b7%b1%e7%9a%84%e6%96%b9%e6%b3%95%e3%80%82/ | 其实我是一个程序员

报歉!评论已关闭.