On Mon, 26 Feb 2007, Kyle Mitchell wrote:

> the following works:
>
> ///// BEGIN funcmeta.rb /////
> def func_meta(&b)
> 	class_eval {
> 		@@proc = b     #guilt begins here
> 		def test
> 			@@proc.call
> 		end
> 	}
> end
>
> class Test
> 	func_meta { puts("test") }
> end
>
> t = Test.new
> t.test
> ///// END funcmeta.rb /////
>
> any clean way to do this without resorting to a class variable?
>
> thanks in advance, you darned helpful people!

harp:~ > cat a.rb
class Module
   def func_meta m, &b
     module_eval{ define_method m, &b }
   end
end

class Test
   func_meta("test"){ puts "test" }
end

t = Test.new
t.test

harp:~ > ruby a.rb
test


-a
-- 
be kind whenever possible... it is always possible.
- the dalai lama