Ruby: What's the use case for Object#send with a static method symbol? -
I am reading the first chapter of "Ruby Best Practice", and this code was thinking about this part of the list :
def text_at (* Args) # Blog inside the category args.inject (hidden) {| S, r | An example of S.send (: at, r)} .inner_text end @feed is notchory :: XML :: node (Representing an XML document), and the method is used to obtain text from a node like this:
self.text_at ('rss', 'title') Like #feed. ('Title') ('RSS'). Inner_text So far, it's great. But why does ... Need to use more vague first version in this case? text_at () use send the object? What is the difference between ...
s.send (: at, r) # option 1 s.at (r) # option 2
When a method is private, it can not be called through your option 2 format, And it has to be called through your option 1 format.
Note This is a general answer to what you said, it can not be relevant to this particular method.
Comments
Post a Comment