《Programming Ruby 中文版第二版》P577页singleton_method_undefined方法说明有点问题

“当一个singleton方法在这个接受者中 没有定义(??)时,singleton_method_undefined作为回调函数会被调用”
这是书上P577页的说法,看看官网的 原文
Invoked as a callback whenever a singleton method is undefined in the receiver
再看代码:
 1 None.gif module Chatty
 2 None.gif     def Chatty . singleton_method_undefined(id)
 3 None.gif       puts  " Undefining #{id.id2name} "
 4 None.gif     end
 5 None.gif     def Chatty . one()   end
 6 None.gif     class  <<  self
 7 None.gif        undef_method( : one)
 8 None.gif     end
 9 None.gif   end
10 None.gif
查找关于 undef_method 的官网说明

Prevents the current class from responding to calls to the named method. Contrast this with remove_method, which deletes the method from the particular class; Ruby will still search superclasses and mixed-in modules for a possible receiver.
《Programming Ruby 中文版第二版》P559页:
阻止当前类响应对这些给定方法的调用。这与remove_method形成鲜明对比;remove_method从这个特定的类中删除方法,而Ruby仍然会从它的超类和mixin的模块中寻找一个可能的接收者。
回到开头,is undefined 就不应该是“没有定义”了,而应该是“被undef_method方法调用后”。

ps:同样的错误可见p557页,关于method_undefined的说明

又ps:extended、method_undefined这两个方法在官网的文档中都没有说明,不知道是不是要发生什么变化?

转载于:https://www.cnblogs.com/bryanzk/archive/2007/07/27/833586.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值