[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Method wrapping

Hal E. Fulton

11/26/2003 5:31:00 PM

I've come late into the thread on this, and I haven't read all
the discussion.

I'll address this to Guy Decoux, as he is one of the top N
most knowledgeable people here, for small values of N.

Guy:

I just have some questions about the way this is going to work
in Rite.

1. Is it possible to add multiple wrappers for a method or
not? Do they "stack"?

2. If they do stack, is it possible to redefine a method as we
are used to doing? Or will that simply add a new wrapper?


Merci,
Hal


28 Answers

ts

11/26/2003 5:35:00 PM

0

>>>>> "H" == Hal Fulton <hal9000@hypermetrics.com> writes:

H> 1. Is it possible to add multiple wrappers for a method or
H> not? Do they "stack"?

H> 2. If they do stack, is it possible to redefine a method as we
H> are used to doing? Or will that simply add a new wrapper?

Only matz know the response to these questions.


Guy Decoux




Hal E. Fulton

11/26/2003 6:19:00 PM

0

ts wrote:
>>>>>>"H" == Hal Fulton <hal9000@hypermetrics.com> writes:
>
>
> H> 1. Is it possible to add multiple wrappers for a method or
> H> not? Do they "stack"?
>
> H> 2. If they do stack, is it possible to redefine a method as we
> H> are used to doing? Or will that simply add a new wrapper?
>
> Only matz know the response to these questions.

OK, I thought maybe it was defined on the core list (which
I don't read).

Matz??

Hal



T. Onoma

11/26/2003 7:04:00 PM

0

On Wednesday 26 November 2003 07:19 pm, Hal Fulton wrote:
> ts wrote:
> >>>>>>"H" == Hal Fulton <hal9000@hypermetrics.com> writes:
> >
> > H> 1. Is it possible to add multiple wrappers for a method or
> > H> not? Do they "stack"?
> >
> > H> 2. If they do stack, is it possible to redefine a method as we
> > H> are used to doing? Or will that simply add a new wrapper?
> >
> > Only matz know the response to these questions.
>
> OK, I thought maybe it was defined on the core list (which
> I don't read).

You ain't miss'n much ;-)




Paul Brannan

11/26/2003 9:52:00 PM

0

On Thu, Nov 27, 2003 at 02:30:36AM +0900, Hal Fulton wrote:
> 1. Is it possible to add multiple wrappers for a method or
> not? Do they "stack"?

IIRC (and if my notes are accurate), I think Matz indicated in his talk
that this would be possible. If there is more than one wrap for a given
method, then the wrap methods are "stacked in order of definition,"
though I'm not sure exactly what that means.

Paul



matz

11/26/2003 11:32:00 PM

0

Hi,

In message "Method wrapping"
on 03/11/27, Hal Fulton <hal9000@hypermetrics.com> writes:

|I'll address this to Guy Decoux, as he is one of the top N
|most knowledgeable people here, for small values of N.
|
|Guy:
|
|I just have some questions about the way this is going to work
|in Rite.

He might have his own version of Ruby with method combination, it's my
responsibility to define Ruby2 behavior:

|1. Is it possible to add multiple wrappers for a method or
|not? Do they "stack"?

They stack.

|2. If they do stack, is it possible to redefine a method as we
|are used to doing? Or will that simply add a new wrapper?

Re-defining primary method (method without :pre, :post, or :wrap)
replaces old primary methods.

matz.

Shashank Date

11/27/2003 12:26:00 AM

0


"Paul Brannan" <pbrannan@atdesk.com> wrote in message
> IIRC (and if my notes are accurate), I think Matz indicated in his talk
> that this would be possible.

Judging from that one occasion when I was sitting next to you,
I have started believing that your notes are pretty accurate, Paul. :-)



Hal E. Fulton

11/27/2003 3:01:00 AM

0

Yukihiro Matsumoto wrote:
> He might have his own version of Ruby with method combination, it's my
> responsibility to define Ruby2 behavior:

Of course.

By the way, I didn't intend any insult or impropriety by asking
this of Guy. I know that you are the ultimate authority, but I
thought that this had perhaps been well-discussed among others
without my knowing.

Frankly, Matz, I feel a little guilty every time I ask you a
question; because I know that every minute you spend answering
that type of question is a minute that you are not spending on
more important matters.

> |2. If they do stack, is it possible to redefine a method as we
> |are used to doing? Or will that simply add a new wrapper?
>
> Re-defining primary method (method without :pre, :post, or :wrap)
> replaces old primary methods.

Since I have already opened this issue, I will clarify by asking
two more specific questions:

1. If I want to redefine a "secondary" method (or whatever I should
call it), can I do so? It seems that an attempt to redefine
foo:pre would simply add a new foo:pre.

2. If the primary method is redefined, do the "secondary" methods
get cancelled? Or do they simply remain in place?

As always, thanks for your time, and thanks for Ruby...

Hal



matz

11/27/2003 6:08:00 AM

0

Hi,

In message "Re: Method wrapping"
on 03/11/27, Hal Fulton <hal9000@hypermetrics.com> writes:

|1. If I want to redefine a "secondary" method (or whatever I should
|call it), can I do so? It seems that an attempt to redefine
|foo:pre would simply add a new foo:pre.

They are auxiliary methods. And "no", you can't "redefine" those
methods. You have to remove them first, using no-yet-designed method
reflection API.

|2. If the primary method is redefined, do the "secondary" methods
|get cancelled? Or do they simply remain in place?

They remain in place. They will be removed altogether when you remove
the method using "remove_method" method.

matz.

T. Onoma

11/27/2003 6:39:00 AM

0

On Thursday 27 November 2003 04:00 am, Hal Fulton wrote:
> Since I have already opened this issue, I will clarify by asking
> two more specific questions:
>
> 1. If I want to redefine a "secondary" method (or whatever I should
> call it), can I do so? It seems that an attempt to redefine
> foo:pre would simply add a new foo:pre.

I doubt we should be able to redine secondary methods. If you do this they
will have to be indexed in someway, and a means for referencing those indexes
becomes neccessary. Because the indexes have no semantic value, they would
not be generally usable. For example, if I had a class using 3 wraps, and you
created a subclass of it that redinfined wrap #2, if I later "improved" my
class by placing another warp before #2, your subclass would no longer work.
(Similiar to below)

> 2. If the primary method is redefined, do the "secondary" methods
> get cancelled? Or do they simply remain in place?

Using just def to redefine method will neccessarily destroy all wraps
otherwise, you run into this:

class A # An external library class
def riot
print "P"
end
end

class B < A # My subclass
def riot
print "Q"
end
end

If later, the library maintainer decided to add an AOP method:

class A # An external library class
def riot
print "P"
end
def riot:wrap
print "*"
end
end

B class will no longer work as expected.

-t0



T. Onoma

11/27/2003 6:46:00 AM

0

On Thursday 27 November 2003 12:32 am, Yukihiro Matsumoto wrote:
> responsibility to define Ruby2 behavior:
> |1. Is it possible to add multiple wrappers for a method or
> |not? Do they "stack"?
>
> They stack.
>
> |2. If they do stack, is it possible to redefine a method as we
> |are used to doing? Or will that simply add a new wrapper?
>
> Re-defining primary method (method without :pre, :post, or :wrap)
> replaces old primary methods.

I would like to point out that their is some inconsistentcy in this behavior,
in that def behaves differently depending on whether it is defined in class
augmentation or a subclass.

class A < X
def riot
super
print "P"
end
end

class A
def riot # this redifines
super
print "R"
end
end

class B < A
def riot
super # this wraps
print "W"
end
end

The def syntax is the same but each has different semantic meaning (effects
code readability/code maintainence).

It is important to understand that Ruby already has a wrapping facility using
subclasses. And singletons act similiarly. So it would be more consistent to
naturally extend that to in-class wraps. We can do this without having to add
special syntax sugar (the colon).

Furthermore, from what I can tell, the current proposal does not address super
wrapping. An issue have delt with in my AOP work.

Please refer to:

http://www.rubygarden.org/ruby?AspectOr...

for more information on all this.

-t0