Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
refactor.rb (decoration plus AOP
Daniel Berger
8/1/2008 3:04:00 AM
Hi all,
Courtesy of Yuki Sonoda, I stumbled across this:
http://gist.githu...
Looks pretty cool to me. Decoration plus AOP!
Ara, have you already done something like this?
Just thought I'd mention it.
Regards,
Dan
1 Answer
Stefan Lang
8/1/2008 11:37:00 AM
0
2008/8/1 Daniel Berger <djberg96@gmail.com>:
> Hi all,
>
> Courtesy of Yuki Sonoda, I stumbled across this:
>
>
http://gist.githu...
>
> Looks pretty cool to me. Decoration plus AOP!
I've written a Python-style-decorators library, too.
(Code is here:
http://repo.or.cz/w/de...
)
Mainly because I don't like Ruby's private/protected methods.
So the library provides decorators to mark single method
definitions as private/protected/public:
require "decorate/private_method"
class Foo
private_method
def foo
...
end
end
Around/before/after methods are also possible:
require "decorate/around_decorator"
class MyObject
extend Decorate::AroundDecorator
around_decorator :log_time, :call => :log_time
def log_time(call)
t0 = Time.now
call.transfer
puts "#{call.receiver}.#{call.message}(#{call.args}) took
#{Time.now - t0} seconds"
call.result
end
log_time
def do_something(x)
sleep(rand(x))
end
end
m = MyObject.new
m.do_something(2)
m.do_something(1)
$ ruby around_example.rb
#<MyObject:0x7fa30c7c9c08>.do_something(2) took 0.998558 seconds
#<MyObject:0x7fa30c7c9c08>.do_something(1) took 1.9e-05 seconds
Stefan
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
refactor.rb (decoration plus AOP
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password