From: Robert Dober Date: 2008-04-25T06:00:38+09:00 Subject: Re: This can't be right On Thu, Apr 24, 2008 at 9:25 PM, Peter Jones wrote: > Simon Krahnke writes: > > Well, helper variables aren't "elegant": > > > > def name > > @name ||= (content_properties.find_by_key('name') || > > Struct.new(:name).new('')).name > > end > > That's basically equivalent to: > > ,---- > | def name > | @name ||= content_properties.find_or_initialize_by_key('name').name.to_s > | end > `---- > > or even this flame bait: > > ,---- > | def name > | @name ||= content_properties.find_by_key('name').name rescue "" > | end > `---- > > Of course, I prefer the former. I do not, because the former will not work when find_or_etc.etc. will return nil Next we shall change the message from #name to #value and that done I have no reason at all to flame ( there is no such thing on this list ;) you at all, I quite like the rescue, it is probable the most readable solution for my eyes. I see yet another alternative which is maybe not the most pretty code, but maybe the easiest to deal with (debugging, evolution of the code) @name ||= content_properties.find...("name") @name &&= @name.value @name ||= "" just a completely different style. Cheers Robert > > -- > Peter Jones [pjones at domain below] > pmade inc. - http://pmade.com > > -- http://ruby-smalltalk.blogspot.com/ --- Whereof one cannot speak, thereof one must be silent. Ludwig Wittgenstein