[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

problem with inheritance and "self"

Giles Bowkett

2/7/2007 12:36:00 AM

I have three classes.

AbstractThing
BlueThing
RedThing

inside AbstractThing:

def self.get
self.find(:first)
end

(yup, it's a Rails app)

I want the DB to only have tables for blue_things and red_things --
but currently, this method gives me a search for abstract_things. The
reason is, the method dispatch pops up to super, finds the method, and
away we go.

How do I redefine this method so I only have to define it inside
AbstractThing, yet when I do, the method dispatch works in such a way
that BlueThing will look for blue_things in the DB, but do it using
AbstractThing's #get() method? In other words -- how do I get the
method to act not from within the superclass which defines it, but the
specific class which uses it?

--
Giles Bowkett
http://www.gilesg...
http://gilesbowkett.bl...
http://gilesgoatboy.bl...

1 Answer

Giles Bowkett

2/7/2007 4:28:00 AM

0

Just want to say, this turned out to be a Rails problem, not a Ruby
thing at all.

On 2/6/07, Giles Bowkett <gilesb@gmail.com> wrote:
> I have three classes.
>
> AbstractThing
> BlueThing
> RedThing
>
> inside AbstractThing:
>
> def self.get
> self.find(:first)
> end
>
> (yup, it's a Rails app)
>
> I want the DB to only have tables for blue_things and red_things --
> but currently, this method gives me a search for abstract_things. The
> reason is, the method dispatch pops up to super, finds the method, and
> away we go.
>
> How do I redefine this method so I only have to define it inside
> AbstractThing, yet when I do, the method dispatch works in such a way
> that BlueThing will look for blue_things in the DB, but do it using
> AbstractThing's #get() method? In other words -- how do I get the
> method to act not from within the superclass which defines it, but the
> specific class which uses it?
>
> --
> Giles Bowkett
> http://www.gilesg...
> http://gilesbowkett.bl...
> http://gilesgoatboy.bl...
>
>


--
Giles Bowkett
http://www.gilesg...
http://gilesbowkett.bl...
http://gilesgoatboy.bl...