pre/post ideas

C

Charles Comstock

Hi,

I wonder if it would be possible if we could define a syntax for multiple
targets on a wrapping method.
class A
def meth1
puts "do stuff1"
end

def meth2
puts "do stuff2"
end

def:pre meth1,meth2
log(args)
end
end

Hmm after writing the example it seems like the

def:pre
def:post

style would show the symantics of this idea through the syntax much nicer
then meth1,meth2 :pre or meth1:pre,meth2:pre.

Of course that last syntax exposes interesting concepts about parallel
method assignment to the same block. I suppose at the moment that is taken
care of with alias, but if you have special syntax on def forms then
alias can't apply to all methods anymore.

In addition it would probably lots of things, but it just seems that
You could potentially be adding the same pre, post, or wrap method
to most of the classes methods and some method to chain the definition
would be nice.

Clearly it would have potential issues with method arity and such,
But it seemed an intriguing concept.

As a related note, what would happen if you unbound a pre,post,wrap method.
Or the method they hook onto. It seems some clarification on differences
between methods/procs will be in order because these AOP methods aren't
really either. Are they first class objects as well? Are they full blown
methods? Can you explicitly name a hook and hook it?

I also was thinking that whichever syntax is worked out for this, assuming
some : syntax exists for extensions to def it would also be nice to be able
to overload this, allowing some interesting potential for programmer defined
syntactic forms.

Just some thoughts I had on these ideas that have been bouncing around in my
head.

Charles Comstock
 
Y

Yukihiro Matsumoto

Hi,

In message "pre/post ideas"

|I wonder if it would be possible if we could define a syntax for multiple
|targets on a wrapping method.

It would be (and is) covered by AspectR.

|As a related note, what would happen if you unbound a pre,post,wrap method.
|Or the method they hook onto. It seems some clarification on differences
|between methods/procs will be in order because these AOP methods aren't
|really either. Are they first class objects as well? Are they full blown
|methods? Can you explicitly name a hook and hook it?

Auxiliary methods are _not_ first class objects, but they are (along
with primary method) attributes of a methods object.

|I also was thinking that whichever syntax is worked out for this, assuming
|some : syntax exists for extensions to def it would also be nice to be able
|to overload this, allowing some interesting potential for programmer defined
|syntactic forms.

I don't know. Flexibility is not always a good thing. It often leas
language designers into temptation.

matz.
 
T

Tim Hunter

I don't know. Flexibility is not always a good thing. It often leas
language designers into temptation.

matz.

LOL! Is somebody writing down all these delightful "Matz-isms?" I think
they'd make great subtitles for the next book about Ruby!
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top