删除一个类的定义
发表于:2006年05月11日  分类:Ruby  添加评论  1,348 次浏览 
  1. class A
  2. end
  3.  
  4. a = A.new
  5.  
  6. puts a.class
  7.  
  8. class Object
  9.   remove_const 'A'
  10. end
  11.  
  12. puts a.class
  13.  
  14. begin
  15.   b = A.new
  16. rescue NameError
  17.   puts 'Not Found Class A'
  18. end

 执行结果:
    A
    A
    Not Found Class A

固定链接: http://liubin.nanshapo.com/2006/05/11/%e5%88%a0%e9%99%a4%e4%b8%80%e4%b8%aa%e7%b1%bb%e7%9a%84%e5%ae%9a%e4%b9%89/ | 其实我是一个程序员

报歉!评论已关闭.