| 赞 | 300 |
| VIP | |
| 好人卡 | |
| 积分 | 242 |
| 经验 | |
| 最后登录 | 2026-10-3 |
| 在线时间 | 9564 小时 |
- 梦石
- 1
- 星屑
- 23241
- 在线时间
- 9564 小时
- 注册时间
- 2012-6-19
- 回帖
- 7018
 
|
发表于 2015-6-22 19:51:36
|
显示全部楼层
- class A
- def m
- msgbox 'It Works !'
- end
- end
- class B
- def self.m
- msgbox 'It Works !'
- end
- end
- a = A.new
- b = B.new
- A.m # => 错误! 方法未定义
- a.m # => It Works !
- B.m # => It Works !
- b.m # => 错误! 方法未定义
复制代码 出错的原因很简单,self.Use 是类方法,你所定义的 set_pixel 是实例方法,类方法 self.Use 执行set_pixel 时查找的是你没有定义的类方法 self.set_pixel 而不是你定义的实例方法 set_pixel ,最终程序没有找到你有定义过任何同名的类方法,自然针对找不到方法报错 |
评分
-
查看全部评分
|