🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.ruby
Article #185

Re: Ruby i dekorator

#185
From: Jaroslaw Zabiello
Date: Thu, 07 Sep 2006 12:36
36 lines
1886 bytes
Dnia Thu, 07 Sep 2006 13:42:42 +0200, Marcin Mielżyński napisał(a):

>> 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

method_added() wyłapuje fakt dodania metody, więc po co mi to? alias nie
potrzebuję, bo chcę zachować tą samą nazwę. A define_method tworzy a nie
odczytuje ciało metody.

> 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()

Tak. W RoR znalazlem blad i chcialem sobie poprawić (kurcze, ze dwa bite
dni straciłem szukając błędu). (http://dev.rubyonrails.org/ticket/6073)
Zanim jednak dodadza (o ile dodadza) to do kodu RoR, wole wykorzystac
otwarte klasy i to sobie dodac w kontrolerze

-- 
Jarosław Zabiełło
http://blog.zabiello.com
Technical Details
Message-ID: <1b5oye9z0x1aq.n67fdxozbl7i.dlg@40tude.net>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!not-for-mail
References: <re7vnvdwaxef.1xsf47isecttl$.dlg@40tude.net> <edp0jp$ph2$1@news.onet.pl>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!not-for-mail
From: Jaroslaw Zabiello <hipertracker@gmail.com>
Newsgroups: pl.comp.lang.ruby
Subject: Re: Ruby i dekorator
Date: Thu, 7 Sep 2006 13:36:30 +0100
Organization: "Portal Gazeta.pl -> http://www.gazeta.pl"
Lines: 36
Message-ID: <1b5oye9z0x1aq.n67fdxozbl7i.dlg@40tude.net>
References: <re7vnvdwaxef.1xsf47isecttl$.dlg@40tude.net> <edp0jp$ph2$1@news.onet.pl>
NNTP-Posting-Host: 213.190.141.10
Mime-Version: 1.0
X-Trace: inews.gazeta.pl 1157632614 10441 213.190.141.10 (7 Sep 2006 12:36:54 GMT)
X-Complaints-To: usenet@agora.pl
NNTP-Posting-Date: Thu, 7 Sep 2006 12:36:54 +0000 (UTC)
X-User: newsgate2006
User-Agent: 40tude_Dialog/2.0.15.1pl
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit