calling an arbitrary superclass method

E

Eric Mahurin

Anybody know of a way to call an arbitrary method in the
superclass? In the current method, you can use "super" to call
the same method of the superclass, but how do you call another?
The only way I can think of off hand is to alias the
superclass methods to something else before creating the
derived class definition. But, that seems kind of ugly. It
seems like there should be a way to call it directly using
superclass or something.




=09
__________________________________=20
Yahoo! Mail Mobile=20
Take Yahoo! Mail with you! Check email on your mobile phone.=20
http://mobile.yahoo.com/learn/mail=20
 
L

Logan Capaldo

Anybody know of a way to call an arbitrary method in the
superclass? In the current method, you can use "super" to call
the same method of the superclass, but how do you call another?
The only way I can think of off hand is to alias the
superclass methods to something else before creating the
derived class definition. But, that seems kind of ugly. It
seems like there should be a way to call it directly using
superclass or something.





__________________________________
Yahoo! Mail Mobile
Take Yahoo! Mail with you! Check email on your mobile phone.
http://mobile.yahoo.com/learn/mail


self.class.superclass.instance_method:)some_method).bind(self).call
(*args)
 
E

Eric Mahurin

--- Logan Capaldo said:
On Jul 3, 2005, at 3:31 PM, Eric Mahurin wrote:
=20
self.class.superclass.
instance_method:)some_method).bind(self).call(*args)

That is the magic I was looking for. Thanks.

I think it would be nice if we had something like this in
Object to make it easier (and faster when written in C):

class Object
def super_method(sym)
self.class.superclass.instance_method(sym)
end
def super_send(sym,*args)
super_method(sym).call(*args)
end
end




=09
____________________________________________________=20
Yahoo! Sports=20
Rekindle the Rivalries. Sign up for Fantasy Football=20
http://football.fantasysports.yahoo.com
 
E

Eric Mahurin

--- Eric Mahurin said:
=20
That is the magic I was looking for. Thanks.
=20
I think it would be nice if we had something like this in
Object to make it easier (and faster when written in C):
=20
class Object
def super_method(sym)
self.class.superclass.instance_method(sym).bind(self)
end
def super_send(sym,*args)
super_method(sym).call(*args)
end
end

Forgot the bind(self). Added it above.


__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around=20
http://mail.yahoo.com=20
 
R

redentis

Eric said:
That is the magic I was looking for. Thanks.

I think it would be nice if we had something like this in
Object to make it easier (and faster when written in C):

class Object
def super_method(sym)
self.class.superclass.instance_method(sym)
end
def super_send(sym,*args)
super_method(sym).call(*args)
end
end

What scenario(s) do you think this would be useful in? Surely the whole
point of the OO principles of polymorphism and implementation hiding is
that you should never need to "call an arbitrary method in the
superclass".

The only case I can think of where you might want to access the
superclass implementation is in an overriding method in a subclass and
at that point 'super' does what you'd expect: gives you essentially
privileged access to the implementation in the super class.
 
E

Eric Mahurin

--- redentis said:
=20
What scenario(s) do you think this would be useful in? Surely
the whole
point of the OO principles of polymorphism and implementation
hiding is
that you should never need to "call an arbitrary method in
the
superclass".
=20
The only case I can think of where you might want to access
the
superclass implementation is in an overriding method in a
subclass and
at that point 'super' does what you'd expect: gives you
essentially
privileged access to the implementation in the super class.

That is exactly what I want to do. I want to be able to call
more than just the superclass method of the same name that
"super" allows me to.

These methods should be "protected" so that only derived
classes are using them.



=09
____________________________________________________=20
Yahoo! Sports=20
Rekindle the Rivalries. Sign up for Fantasy Football=20
http://football.fantasysports.yahoo.com
 

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,781
Messages
2,569,616
Members
45,306
Latest member
TeddyWeath

Latest Threads

Top