Chinaunix首页 | 论坛 | 博客
  • 博客访问: 62322
  • 博文数量: 33
  • 博客积分: 841
  • 博客等级: 准尉
  • 技术积分: 340
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-20 20:54
文章分类

全部博文(33)

文章存档

2011年(33)

分类: Python/Ruby

2011-02-18 16:28:45

  1. #公共类方法的定义
  2. class SpecialTest
  3.         def meth1
  4.             puts "This is meth1"
  5.         end

  6.         def meth2
  7.             puts "This is meth2"
  8.         end
  9. end

  10. obj1 = SpecialTest.new
  11. obj2 = SpecialTest.new

  12. #特殊类的定义,class << 代表它的特殊类
  13. class << obj2
  14.         def meth1
  15.             puts "This is obj2's meth1"
  16.         end
  17.     
  18.         def meth2
  19.             puts "This is obj2's meth2"
  20.         end
  21. end

  22. obj1.meth1
  23. obj1.meth2
  24. obj2.meth1
  25. obj2.meth2
阅读(726) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~