クラスメソッドについて

クラスメソッドの定義を見ていきます。

class Hoge
  def self.hello
    puts 'hoge'
  end
end

Hoge.hello
=>hoge

これは標準的な書き方だと思います。

この時のselfはクラス自身(ここではHoge)を見ています。

class Hoge
  def Hoge.hello
    puts 'hoge'
  end
end

Hoge.hello
=>hoge

Hogeに対しての特異メソッドになります。

これが成り立つのならば下も成り立ちます。

class Hoge
end

def Hoge.hello
  puts 'hello'
end

Hoge.hello

クラスメソッドは、クラスオブジェクトに対しての特異メソッドということです。