Horst DuchóÏe () wrote:
[...]
> while looking for a technique for redefining the singleton function
> TkCore.callback in a similar way as described in the PP Ruby book for
> Kernel.system (see p. 269) using alias_method

After giving it a closer look, I believe that singleton methods (those
include module functions) cannot be aliased, because they are already
bound to a receiver (my understanding of the ruby sources is still
partial, so I may be off). "system" is a special case, because it's
found as a method in Object, which is the only "superclass" that
modules have (somebody correct me if I'm wrong). alias_method is
mainly useful for getting a copy of a method that you are about
to redefine for inheritance.

> I finally arrived at the
> following solution that I am not satisfied with (because it uses a
> global variabel):

You may want to store it in a class variable (say, @@old_callback),
which apparently is available not only in a module or class, but
also in all descendants (Matz, is this the intended behavior? I
think its very useful). So, your code would become:

>   $old_callback = TkCore.method(:callback)
>   def TkCore.callback(arg)
>     begin
>       $old_callback.call(arg)
>     rescue Exception => ex
>       # Display message in statusline:
>       msg ("Fehler: " + ex)
>     end
>   end

module TkCore

  @@old_callback = TkCore.method(:callback)

  def TkCore.callback(arg)
    begin
      @@old_callback.call(arg)
    rescue Exception => ex
      msg "Fehler: #{ex.inspect}"
    end
  end

end

Hope this helps.

			Reimer Behrends