Matteo Gottardi
7/6/2007 9:11:00 AM
Hi all. How can I "decorate" a method? In python I do:
---- begin code ----
def decorato(func):
def decor(*args):
print "Before"
func(*args)
print "After"
return decor
@decorato
def metodo():
print "metodo"
metodo()
---- end code ----
and it will print:
Before
metodo
After
How can I make the same in ruby? I tried to look functions like "public"
or "private", but they are implemented in C, not in ruby...
PS: I'm not looking at a "decorate" syntax, only at a method that take a
method and returns a modified one...
For example:
def metodo
puts "metodo"
end
decorate :metodo
How can I implement the "decorate" function?
Thanks in advance, and please excuse my bad english...
--
* Matteo Gottardi | matgott@tin.it
* ICQ UIN 20381372
* Linux - the choice of a GNU generation
* GPG Fingerprint:
* B9EE 108F 52C8 D50C B667 B1F2 AB56 8A01 BA3D 36A1