Gaspard Bucher
9/14/2007 9:34:00 AM
Is this what you are looking for ?
class Module
def funky_define_method(*args, &block)
puts "#{args[0]} is being defined"
define_method(*args, &block)
end
end
class Parrot
funky_define_method(:hello) do |msg, name|
printf(msg,name)
end
end
Parrot.new.hello("Hello %s !\n", 'Josip')
2007/9/14, Josip Gracin <gracin@tel.fer.hr>:
> Hello! A newbie question.
>
> Here's what I'd like to be able to do.
>
> #============================================
> def_init_function( :system_init ) do |x,y|
> ...something...
> end
>
> def_init_function( :timers_init ) do |a|
> ...another body...
> end
>
> ..and later...
> system_init(2,3)
> timers_init(0)
> #============================================
>
>
> In addition to defining a function, the def_init_function() will perform
> some additional book-keeping. The question is: how do implement
> def_init_function()? (The syntax need not be exactly like in the
> example above.)
>
> I've tried various ways (using define_method, eval) but I couldn't make
> it do what I want.
>
> Thanks in advance!
>
>