In Ruby, what is the difference between a class method and a class's singleton method? -


I have seen it in the first code and I have read about it in The Well Grounded Rubiist by David A. Black, but There is no instance of use cases, to help me understand why someone has to define singleton method in class like this:

  class vehicle class   

How to do the above method on a different class than a normal class method:

  class auto def self #All_makes # Some code end-end  

Yehuda Katz has an outstanding writing gap (other things Between) you can find it.

To summarize you briefly. When you define the class, the itself refers to the keyword class. Therefore, when you do self.method , you can add a new method to the person class Defining each class has a metaclass, also called singleton class, which can be accessed and modified. Class & lt; & Lt; Self you are opening the idolton class and amending that value. Functionally, the result is the same, but the modified class is different.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -