Article View: pl.comp.lang.ruby
Article #184Re: Ruby i dekorator
From: Marcin Mielżyński
Date: Thu, 07 Sep 2006 11:42
Date: Thu, 07 Sep 2006 11:42
24 lines
1360 bytes
1360 bytes
Jaroslaw Zabiello wrote:
> Jak w Ruby zaimplementować pythonowy dekorator? A może jest jakaś metoda
> która wyciąga całe ciało funkcji? Chcę coś dodać przed nim i po nim..
>
można skorzystać np z method_added alias i define_method
domyślam się że chodzi o coś takiego w pythonie: ?
def around(fun):
def x(self):
print "pre"
fun(self)
print "post"
return x
class A:
@around
def m(self):
print "!"
A().m()
lopex
Technical Details
Message-ID:
<edp0jp$ph2$1@news.onet.pl>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!newsfeed.gazeta.pl!news.onet.pl!not-for-mailReferences:
<re7vnvdwaxef.1xsf47isecttl$.dlg@40tude.net>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!newsfeed.gazeta.pl!news.onet.pl!not-for-mail From: Marcin Mielżyński <lopx@gazeta.pl> Newsgroups: pl.comp.lang.ruby Subject: Re: Ruby i dekorator Date: Thu, 07 Sep 2006 13:42:42 +0200 Organization: Onet.pl Lines: 24 Message-ID: <edp0jp$ph2$1@news.onet.pl> References: <re7vnvdwaxef.1xsf47isecttl$.dlg@40tude.net> NNTP-Posting-Host: cuo178.internetdsl.tpnet.pl Mime-Version: 1.0 X-Trace: news.onet.pl 1157629370 26146 83.19.70.178 (7 Sep 2006 11:42:50 GMT) X-Complaints-To: usenet@news.onet.pl NNTP-Posting-Date: Thu, 7 Sep 2006 11:42:50 +0000 (UTC) X-Sender: 5Da2qcG7AWj7WISFX859Php/OS6q4VnB In-Reply-To: <re7vnvdwaxef.1xsf47isecttl$.dlg@40tude.net> User-Agent: Thunderbird 1.5.0.5 (Windows/20060719) Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit