From: Lyle Johnson Date: 2008-04-24T23:53:39+09:00 Subject: Re: This can't be right On Thu, Apr 24, 2008 at 9:25 AM, Stefan Kroes wrote: > I'm pretty new to Ruby and RoR but I'm trying to learn for a large > project. I wrote the following method in one of my models but it can't > be the right way to do this because ruby should be able to do it way > more concisely. Can you tell me of a better way? > > def name > if !@name > property = content_properties.find_by_key('name') > if property > @name = property.value > else > @name = "" > end > else > @name > end > end Here's one slightly shorter version: def name unless @name property = content_properties.find_by_key('name') @name = property ? property.value : "" end @name end Hope this helps, Lyle