Singleton method vs. class method

后端 未结 5 837
一向
一向 2021-02-08 16:31

Are class method and singleton method doing the same or different? Here is an example.

class C
  def self.classmethod
    puts \"class method #{self}\"
  end
end         


        
5条回答
  •  梦如初夏
    2021-02-08 16:39

    They are relative notions; matter of perspective. What is its instance method from the point of view of a singleton class of class A is a class method from the point of view (of an instance) of A.

提交回复
热议问题