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 text_at () use send the object? What is the difference between ...

  s.send (: at, r) # option 1 s.at (r) # option 2  

... Need to use more vague first version in this case?

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

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -