On Sun, 15 Oct 2006, John Ky wrote:

>>>>>> 
> def define_my_method(method_name)
> define_method method_name do
>   yield
> end
> end
>
> class X
> define_my_method :method1 do
>   puts "Method 1"
> end
> define_my_method :method2 do
>   puts "Method 2"
>   method1
> end
> end
>
> X.new.method2
> <<<<<
>
> Gives:
>
> C:\wrk\johnk\wiksprint-001>define.rb
> Method 2
> C:/wrk/johnk/wiksprint-001/define.rb:13: undefined local variable or method 
> `met
> hod1' for X:Class (NameError)
>       from C:/wrk/johnk/wiksprint-001/define.rb:3:in `method2'
>       from C:/wrk/johnk/wiksprint-001/define.rb:17

you don't want yield here as the context of that yield is bound to the
__class__ (think of what self is at the time of call) and you want it bould to
the instance.

   harp:~ > cat a.rb
   def define_my_method *a, &b
     define_method *a, &b
   end

   class X
     define_my_method :method1 do
       puts "Method 1"
     end
     define_my_method :method2 do
       puts "Method 2"
       method1
     end
   end

   X.new.method2

   harp:~ > ruby a.rb
   Method 2
   Method 1


your metaprogramming is fine - this is an issue of blocks and scoping.

regards.

-a
-- 
my religion is very simple.  my religion is kindness. -- the dalai lama