>  module_eval do
>    def test2 *args
>      p [:test2, args, block_given?]
>    end
>  end

The problem is that, in my situation, the name of the method
("test2") is not fixed, but stored in a string, like this:

 method_name = "test2"
 module_eval do
   def #{method_name}(*args, &block) # Won't work!
     p [method_name, args, block_given?]
   end
 end

One way to overcome this, without putting the whole method in
one big string, is using a temporary method, like this:

 method_name = "test2"
 module_eval do
   def temp_method(*args, &block)
     p [method_name, args, block_given?]
   end
   eval("alias :#{method_name} :temp_method")
   undef :temp_method
 end

See code below, Test#test4.

Comments? Suggestions?

Thanks.

gegroet,
Erik V. - http://www.erikveen.dds.nl/

----------------------------------------------------------------

 class Test
   def test1(*args, &block)
     p [:test1, self, args, block_given?]
   end

   define_method(:test2) do |*args|
     p [:test2, self, args, block_given?]
   end

   module_eval do
     def test3(*args, &block)
       p [:test3, self, args, block_given?]
     end
   end

   method_name   = "test4"
   module_eval do
     def temp_method(*args, &block)
       p [:test4, self, args, block_given?]
     end
     eval("alias :#{method_name} :temp_method")
     undef :temp_method
   end
 end

 t       = Test.new

 t.test1(1, 2, 3){}
 t.test2(1, 2, 3){}
 t.test3(1, 2, 3){}
 t.test4(1, 2, 3){}

----------------------------------------------------------------