Q&A about the _method_ meaning?
来源:互联网 发布:linux 命令下载文件 sz 编辑:程序博客网 时间:2024/06/05 00:47
<Q>In the file lib/find.rb (1.9.3):
def find(*paths) # :yield: path
block_given? or return enum_for(__method__, *paths)
...........
def find(*paths) # :yield: path
block_given? or return enum_for(__method__, *paths)
...........
<A>Kernel#__method__ returns the name of the method being defined as asymbol (or nil if called outside a method definition). In that case itreturns :find.Kernel#__callee__ is similar, but it returns the name of the method asused by the caller in that particular invocation. In that case thereturned symbol could be different if the caller invoked an alias.The benefit of not hard-coding the method name is similar to nothard-coding a constant name in code like self.class.class_methodYou just do not rely on the constant name of the object's class andthe code has one less dependency in case of a refactor.Similarly, you could hard-code :find, it would not be the end of theworld, but __method__ makes that unnecessary. If it is computable,better not to repeat it.
0 0
- Q&A about the _method_ meaning?
- Q&A about volatile & const(Z)
- Q&A about volatile & const(Z)
- Q&A about Integration Management Processes
- Q\A about VME bus for Vxworks
- Q\A about VME bus for Vxworks 2
- The Q&A during Webkit learning.
- about the blog, a new friend
- A template about the nandflash driver
- Just a complaint about the college examinations
- A small test demo about the ++ operator
- The meaning of Bill Gates
- The Real Meaning of Peace
- CSDN, what's the meaning.
- The Meaning of Class Definitions
- the meaning of extern "C"
- The meaning of static keywords
- The meaning of true love
- HDU5007 Post Robot
- HDU5007 Post Robot
- 2015百度校园招聘机器学习/数据挖掘工程师笔试题(笔试时间:2014-9-14,哈尔滨站)
- ubuntu10.04的学习小结
- 异常处理
- Q&A about the _method_ meaning?
- 面向对象程序设计上机练习七(类和对象)
- 电面小记
- Redis源码学习-AOF
- C#操作字符串总结
- OA_1界面
- 最长公共子串(LCS)
- Example 2.3 n皇后问题
- 18. 转换