On Sunday 02 February 2003 03:34 am, Mauricio FernáÏdez wrote:

your NoOverloading code looks fantastic!

i must say i expected to be told it wasn't possible. awesome that you were 
able to put together a nice solution so quickly. thank you. thank you. thank 
you. definitely going into my general library of tools. and truly this (or 
its kin written in c) should be considered for inclusion in Ruby proper!

-transmai

> Forget that code, the following is much better as now:
>  * you can use no_redef before defining methods in the base class, only
>    derived classes are affected
>  * you can "stack" the restrictions, ie if you have C < B < A, you can
>    specify that some methods of A shouldn't be overloaded, and later
>    that some in B shouldn't be either, and it'll just work.
>
> And it gives a nice example of what class instance variables are good
> for :-)
>
> Drawback: method definition is somewhat slower, but _only_ definition.
>
> batsman@tux-chan:/tmp$ expand -t 2 f.rb
> module NoOverloading
>   def no_redef(*args)
>     @no_override ||= []
>     args.each { |i| @no_override << i }
>   end
>
>   def __no_redef_list__
>     supmethods = []
>     (ancestors - [self]).each do |i|
>       begin
>         supmethods += ( i.__no_redef_list__ || [])
>       rescue NameError
>       end
>     end
>     (@no_override || []) + supmethods
>   end
>
>   def inherited sub
>     class << sub
>       def method_added(id)
>         return if __no_redef_list__.index(id) == nil
>         remove_method id
>       end
>     end
>   end
>
> end

-- 
tom sawyer, aka transami
transami / transami.net