Singleton method vs. class method

后端 未结 5 838
一向
一向 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:57

    There is no difference. There are no class methods in Ruby. "Class method" is just a name that we humans call a singleton method if the object happens to be an instance of the Class class.

提交回复
热议问题