[Ruby2]how to dynamically attach :pre :post :wrap ro methods?

G

gabriele renzi

Hi gurus and nubys,

Loooking forward to the syntax

def foo:pre
end

I wonder: could we add preconditions without resorting to syntax?

Would we have something like this:

myobj.methods.each do |m|
m.wrap:)pre) {|*args| p args }
end

?
Sounds obvious and necessary to me, but I can't remeber talks about
this..


TIA
 
M

Mauricio Fernández

Would we have something like this:

myobj.methods.each do |m|
m.wrap:)pre) {|*args| p args }
end

?
Sounds obvious and necessary to me, but I can't remeber talks about
this..

See
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/97440

Something similar can be implemented trivially using the same principle,
with Object#method instead of Module#instance_method and using the
singleton class.

--
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

...Deep Hack Mode -- that mysterious and frightening state of
consciousness where Mortal Users fear to tread.
-- Matt Welsh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top