惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
J
Java Code Geeks
I
InfoQ
V
Visual Studio Blog
M
MIT News - Artificial intelligence
H
Help Net Security
博客园_首页
Blog — PlanetScale
Blog — PlanetScale
F
Fortinet All Blogs
Apple Machine Learning Research
Apple Machine Learning Research
人人都是产品经理
人人都是产品经理
G
Google Developers Blog
A
About on SuperTechFans
腾讯CDC
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Last Week in AI
Last Week in AI
小众软件
小众软件
aimingoo的专栏
aimingoo的专栏
罗磊的独立博客
大猫的无限游戏
大猫的无限游戏
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
云风的 BLOG
云风的 BLOG
S
SegmentFault 最新的问题
WordPress大学
WordPress大学

博客园 - 小熊bryan

坐视——做事——做势 InfoQ中文站正式升级为1.5版 编辑絮语 今年…… 书店的风景 要敏捷一点,再敏捷一点 对Ruby中Kernel的callcc方法的研究 理解ruby核心概念:Object, Class, Module, Kernel 再试试看 越来越觉得自己的博客像个包子 翻译作品:为敏捷团队设计协作空间 用元编程的方式向Ruby添加properties 【翻译】在ruby中实现attributes的lazily initialization(惰性初始化) 是没有好音乐,还是我们没有好心境? Best of Ruby Quiz 之四 Animal Quiz之我的答案 Best of Ruby Quiz 笔记之三:GEDCOM Parser 使用REXML在ruby中处理xml 软件的业务价值来自哪里?——business value generally comes from using software 要问五次为什么--业务需求挖掘之道(摘自Wikipedia)
《Programming Ruby 中文版第二版》P577页singleton_method_u...
小熊bryan · 2007-07-27 · via 博客园 - 小熊bryan

“当一个singleton方法在这个接受者中没有定义(??)时,singleton_method_undefined作为回调函数会被调用”
这是书上P577页的说法,看看官网的原文
Invoked as a callback whenever a singleton method is undefined in the receiver
再看代码:

 1module Chatty
 2     def Chatty.singleton_method_undefined(id)
 3       puts "Undefining #{id.id2name}"
 4     end
 5     def Chatty.one()   end
 6     class << self
 7        undef_method(:one)
 8     end
 9   end
10

查找关于 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这两个方法在官网的文档中都没有说明,不知道是不是要发生什么变化?