Hello,

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 I finally arrived at the
following solution that I am not satisfied with (because it uses a
global variabel):

  $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

or more abstract:

module A
  def A.m
    'A.m'
  end
end
A.m                             # => "A.m"

$old_m = A.method(:m)           # Don't like this
def A.m
  "new_m " + $old_m.call
end

A.m                             # => "new_m A.m"

Is there a better way to do this? I did not find a solution using aliasing.

Thinking about singleton functions I came across another oddity I cannot
explain myself:

module M
  # Define a singleton method for M
  def M.m
    puts 'M.m'
  end
end
M.singleton_methods             # => ["m"] OK

class A
  include M
end

A.singleton_methods             # => [] Hmm! Singletons get not included!

def A.sm
  puts 'A.sm'
end
A.singleton_methods             # => ["sm"] OK

class B < A
end
B.singleton_methods             # => ["sm"] Singletons get inherited!
                                # Why here but not with modules?