Rubyでクラスメソッドをundefする時のメモ。
まずは以下のようにクラスメソッドを定義し、undefする。

class A
  def A.msg
    puts "class method"
  end
end

class A
  undef A.msg
end

結果、エラーになる。
undefメソッドはシンボルまたは識別子を受け付けるけど、A.msgだと識別子としては認識してくれないみたい。

対策

クラスを再オープンする。

class << A
  undef msg
end

これでundefできました。

ちなみに、undef_methodも同じようにクラスの再オープンをしないとエラーになる。