Hi, I am a newbie in ruby. I try to read the stdlib code to learn ruby.
I got confused In the file lib/find.rb (1.9.3):
def find(*paths) # :yield: path
block_given? or return enum_for(__method__, *paths)
what is the __mothed__ meaning? And How does eunm_for return a enumerator.
PS: I am a new English learner, so .... sorry for the mistakes in English . And This is my first time useing the maillist, is there any important rule I should followed?
Looking forword to your reply.
Thanks a lot!!!
Kernel#__method__ returns the name of the method being defined as a
symbol (or nil if called outside a method definition). In that case it
Kernel#__callee__ is similar, but it returns the name of the method as
used by the caller in that particular invocation. In that case the
returned symbol could be different if the caller invoked an alias.
The benefit of not hard-coding the method name is similar to not
hard-coding a constant name in code like
You just do not rely on the constant name of the object's class and
the code has one less dependency in case of a refactor.
Similarly, you could hard-code :find, it would not be the end of the
world, but __method__ makes that unnecessary. If it is computable,
better not to repeat it.