classComputer# Eğer method __ ile başlıyorsa, veya method_missing ise veya respond_to ise# methodu çıkarma. instance_methods.eachdo|m|# undef_method kullandığımız zaman üst sınıflardan inherit edilen # tüm methodlar çıkarılır.undef_methodmunlessm.to_s=~/^__|^method_missing$|^respond_to\?$/endend
c=Computer.newbeginc.inspectrescueException=>eputs"inspect methodu undef_method ile cikarilmis: #{e.message}"end
classMonitor# inspect methodu Monitor classında tanımlanmadığı için remove_method# ile çıkarılamaz.beginremove_method:inspectrescueException=>eputse.messageend# remove_method sadece o sınıfa ait methodları çıkarır. Inherit edilen# methodlara dokunmaz. O yüzden burda inherit edilen bir methodu# remove_method ile çıkarmaya çalıştığımız zaman hata verir.puts"hello methodunu remove_method ile cikariyoruz"remove_method:helloend