From: "ara.t.howard" Date: 2008-08-16T00:18:57+09:00 Subject: Re: Best practice for set-and-test idiom? --Apple-Mail-1--11666981 Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit On Aug 15, 2008, at 8:12 AM, Gavin Sinclair wrote: > Does the Model.find(...) need to be buried in a test condition? If > it's retrieving worthwhile data, it's worth a line of its own. spoken like someone who has debugged code from logs more than once ;-) > > > model = Model.find(...) > val = (model && model.attribute) || DEFAULT > > The second line could be called idiomatic Ruby. Whether it appeals to > you or not, I can't predict :) > > For situations where more complex processing is required before > setting the variable, I am a _big_ fan of these: > > val = > if condition then > processing > processing > value1 > else > processing > value2 > end > > val = > case x > when 1: ... > when 2: ... > ... > end me too - the indent is a great indicator. sometimes i even do val = ( if condition then processing processing value1 else processing value2 end ) for more visual distinction cheers. a @ http://codeforpeople.com/ -- we can deny everything, except that we have the possibility of being better. simply reflect on that. h.h. the 14th dalai lama --Apple-Mail-1--11666981--