From: Logan Capaldo Date: 2007-08-14T20:03:32+09:00 Subject: Re: Need help cleaning up a model method ------=_Part_35173_31550098.1187089408065 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On 8/14/07, Giant Cranes wrote: > > Hi, > > I need a little help cleaning up the method below. In my .NET days I > would have let this pass, but I am trying to be a good ruby citizen by > keeping things simple. > > This is from a seller model which has many vehicles: > > def total_retail_price > if @@total_retail_price.nil? > @@total_retail_price = self.vehicles.sum(:retail_price) > @@total_retail_price = 0 unless @@total_retail_price > end > @@total_retail_price > end > > If I didn't have to worry about the seller having 0 vehicles I could > just use: > > def total_retail_price > @@total_retail_price ||= self.vehicles.sum(:retail_price) > end > > Does anyone have any suggestions on how I can fix improve on this? sum should be zero for no vehicles though, shouldn't it? Thanks, > GiantCranes > -- > Posted via http://www.ruby-forum.com/. > > ------=_Part_35173_31550098.1187089408065--