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
returns :find.
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
self.class.class_method
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.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.