[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

alias_method 'stickiness'

Ara.T.Howard

3/13/2006 12:48:00 AM

4 Answers

Joel VanderWerf

3/13/2006 2:29:00 AM

0

Ara.T.Howard wrote:
>
> any idea if this behaviour is intended or not?
>
>
> mussel:~/eg/ruby/nrtlib/nrtlib-0.0.0 > cat a.rb
> #
> # the problem
> #
> module NRT
> class Subscription
> def process_incoming
> raise NotImplementedError
> end
> alias_method "run", "process_incoming"

Unfortunately (?) what this^^^ does is define run to be a copy of the
method process_incoming, rather than define run as a method that
delegates to process_incoming.

I suppose this behavior is necessary if you want to use alias_method to
wrap an old method, regardless of what gets redefined in child classes.

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407


Ara.T.Howard

3/13/2006 2:54:00 AM

0

Joel VanderWerf

3/13/2006 8:00:00 PM

0

ara.t.howard@noaa.gov wrote:
> On Mon, 13 Mar 2006, Joel VanderWerf wrote:
>
>> Ara.T.Howard wrote:
>>>
>>> any idea if this behaviour is intended or not?
>>>
>>>
>>> mussel:~/eg/ruby/nrtlib/nrtlib-0.0.0 > cat a.rb
>>> #
>>> # the problem
>>> #
>>> module NRT
>>> class Subscription
>>> def process_incoming
>>> raise NotImplementedError
>>> end
>>> alias_method "run", "process_incoming"
>>
>> Unfortunately (?) what this^^^ does is define run to be a copy of the
>> method process_incoming, rather than define run as a method that
>> delegates to process_incoming.
>>
>> I suppose this behavior is necessary if you want to use alias_method to
>> wrap an old method, regardless of what gets redefined in child classes.
>
> doh! yup - yer right. i like my 'anonym' method more and more.
> perhaps an
> option to alias_method like
>
> alias_method "foo", "bar", :dup => false
>
> or, more concise
>
> alias_method "foo", "bar", false
>
> though i detest dangling bool arguments (method(true, false, true, true,
> false) acckkkk!)...
>
> either that or alias_method should be renamed copy_method ;-)

I've just gotten used to using alias *only* for metaprogramming, and not
for ordinary API definition.

Maybe it would be nice if the alias keyword were reserved for the
delegation style definition, like your anonym method, and the
metaprogramming interface were something like this:

class Foo
# alias :m_copy :m # old way
instance_method_at[:m_copy] = instance_method(:m) # new way
# now you can wrap :m_copy however you want
end

This makes it more clear that you are making a copy, so it might be less
confusing.

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407


Ara.T.Howard

3/13/2006 8:53:00 PM

0