On Tue, 6 Jan 2004, Jamis Buck wrote:

> Charles Comstock wrote:
> 
> >If I have code like:
> >
> >class A
> >	def foo
> >		puts "A::foo"
> >	end
> >end
> >
> >class B < A
> >	def foo
> >		puts "B::foo"
> >	end
> >	def bar
> >		# call A::foo
> >	end
> >end
> >
> >Is there a legal way to call A::foo from B::bar?
snip
> 
> There is a way,  and it's ugly, but it goes something like this:
> 
>   def bar
>     A.instance_method( :foo ).bind( self ).call
>   end
> 
> In other words, you get the unbound version of 'foo' from A, bind it to 
> the current instance of B, and invoke it.  If there is a cleaner way, I 
> don't know it, but would love to hear about it.
> 
> 

Gah that's nasty.  You can get the superclass automatically with 

self.class.superclass

so I guess you can do it with

self.class.superclass.instance_method( :foo ).bind(self).call

so I wonder if there is a way to make a singleton or temporary class
which could be returned by say parent allowing you to just use

parent.foo

to just do all of above.  Clearly this doesn't seem to be something
that is supposed to be easy.  Perhaps someone knows why?  

Thanks for the help anyway,

Charlie