Howdy. For the last several years I''ve primarily been doing WebObjects development but I decided to try out RoR. I''m now gearing up to rewrite an existing app using RoR. I''ve read the beta book and as much online material as I can get my hands on but I have a question. Forgive me if I am asking a naïve RoR question. In WebObjects (WO), my data model could consist of a superclass called ContentItem. This superclass contains only a single attribute, name. The subclasses could define specific types of content items that would override the name attribute/method. The benefit is I could then create a component (partial page fragment) that listed a series of ContentItem objects (the superclass) but I could pass in an array of any type of the subclass. A single ''listing component'' could be re-used all over the app to list any type of ContentItem. I see that RoR does single table inheritance and I think I could use that to accomplish this. I''m not a huge fan of STI. Is there a way in RoR to accomplish the equivalent without using STI? Remember, I''m new here... If I''m missing something painfully obvious (possible), be gentle. :-) Thanks again, Hunter
On Tue, 28 Jun 2005, Hunter Hillegas wrote:> For the last several years I''ve primarily been doing WebObjects > development but I decided to try out RoR. I''m now gearing up to rewrite > an existing app using RoR.Ah, another on the same path. :)> I''ve read the beta book and as much online material as I can get my > hands on but I have a question. Forgive me if I am asking a naïve RoR > question. > > In WebObjects (WO), my data model could consist of a superclass called > ContentItem. This superclass contains only a single attribute, name. > > The subclasses could define specific types of content items that would > override the name attribute/method. > > The benefit is I could then create a component (partial page fragment) > that listed a series of ContentItem objects (the superclass) but I could > pass in an array of any type of the subclass. A single ''listing > component'' could be re-used all over the app to list any type of > ContentItem.So, you might have a ContentItem subclass of Ad or Article, am I getting what you mean?> I see that RoR does single table inheritance and I think I could use > that to accomplish this. I''m not a huge fan of STI.Ruby isn''t strictly STI, though, because it can be hierarchy-blind.> Is there a way in RoR to accomplish the equivalent without using STI?Are you familiar at all with the concept of duck typing? (If it acts like a duck, it must be a duck) I don''t fully get it (yet), but I think that may be the answer to your question.> Remember, I''m new here... If I''m missing something painfully obvious > (possible), be gentle. :-)http://www.answers.com/topic/duck-typing http://www.rubygarden.org/ruby?DuckTyping http://www.ruby-talk.org/cgi-bin/scat.rb/ruby/ruby-talk/100511 This one includes some interesting discussion: http://www.beust.com/weblog/archives/000269.html -- _Deirdre web / blog: http://deirdre.net/ yarn: http://fuzzyorange.com cat''s blog: http://fuzzyorange.com/vsd/ "Memes are a hoax! Pass it on!"
> From: Deirdre Saoirse Moen <deirdre-mzk6fgDMp2XR7s880joybQ@public.gmane.org> > Reply-To: <rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org> > Date: Tue, 28 Jun 2005 15:59:31 -0700 (PDT) > To: Rails <rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org> > Subject: Re: [Rails] Rails Inheritance Question > > On Tue, 28 Jun 2005, Hunter Hillegas wrote:...>> I''ve read the beta book and as much online material as I can get my >> hands on but I have a question. Forgive me if I am asking a naïve RoR >> question. >> >> In WebObjects (WO), my data model could consist of a superclass called >> ContentItem. This superclass contains only a single attribute, name. >> >> The subclasses could define specific types of content items that would >> override the name attribute/method. >> >> The benefit is I could then create a component (partial page fragment) >> that listed a series of ContentItem objects (the superclass) but I could >> pass in an array of any type of the subclass. A single ''listing >> component'' could be re-used all over the app to list any type of >> ContentItem. > > So, you might have a ContentItem subclass of Ad or Article, am I getting > what you mean?Precisely.> >> I see that RoR does single table inheritance and I think I could use >> that to accomplish this. I''m not a huge fan of STI. > > Ruby isn''t strictly STI, though, because it can be hierarchy-blind. > >> Is there a way in RoR to accomplish the equivalent without using STI? > > Are you familiar at all with the concept of duck typing? (If it acts like > a duck, it must be a duck) > > I don''t fully get it (yet), but I think that may be the answer to your > question.Not familiar but I will read your links below. Cheers!> >> Remember, I''m new here... If I''m missing something painfully obvious >> (possible), be gentle. :-) > > http://www.answers.com/topic/duck-typing > http://www.rubygarden.org/ruby?DuckTyping > http://www.ruby-talk.org/cgi-bin/scat.rb/ruby/ruby-talk/100511 > > This one includes some interesting discussion: > http://www.beust.com/weblog/archives/000269.html