From: "Mauricio Fernández" Date: 2003-02-02T18:41:45+09:00 Subject: Re: no override On Sun, Feb 02, 2003 at 04:51:08PM +0900, Tom Sawyer wrote: > is there any way to specifiy that a method can not be overrided? perfereably > without throwing an error; rather if you try to override the method it simply > dosen't happen. Kind of evil, but works: batsman@tux-chan:/tmp$ expand -t 2 f.rb module NoOverloading @@no_override = [] def no_redef(*args) args.each { |i| @@no_override << i } end def method_added(id) return if @@no_override.index(id) == nil remove_method id end end class A extend NoOverloading def a; puts "A#a"; end def b; puts "A#b"; end no_redef :a, :b # do it after defining the methods :) end class B < A def a; puts "B#a"; end def b; puts "B#b"; end end b = B.new b.a b.b batsman@tux-chan:/tmp$ ruby f.rb A#a A#b -- _ _ | |__ __ _| |_ ___ _ __ ___ __ _ _ __ | '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ | |_) | (_| | |_\__ \ | | | | | (_| | | | | |_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_| Running Debian GNU/Linux Sid (unstable) batsman dot geo at yahoo dot com 'Ooohh.. "FreeBSD is faster over loopback, when compared to Linux over the wire". Film at 11.' -- Linus Torvalds