From: Robert Klemme Date: 2012-02-01T22:25:39+09:00 Subject: Re: Multiple assignment in conditional On Wed, Feb 1, 2012 at 1:42 PM, Gavin Sinclair wrote: > On Wed, Feb 1, 2012 at 11:33 PM, Robert Klemme > wrote: >> >> There are plenty more solutions, for example: > > Both contain this, which I think is rather ugly: > >>   week_and_day[0] += @t1.number_of_weeks > > Ruby is beautiful for many reasons.  One of those is the ability to > return multiple values in a nice syntactic way.  These solutions are > not embracing that; they are working with an array instead of with two > values. > > Alternatives aside, what do you think of my preferred solution? On first sight it looks like it's probably the best solution for the given setting. But I cannot get rid of that nagging feeling in the back of my head that something is totally wrong here. I just can't put my finger on it. :-) Maybe it's that we have methods here which are intended to return two values but actually there is a special case of nil being returned for the _array_ of two. I can't test on 1.9.* right now but in 1.8.7 (a,b=nil) is always an empty array => true. So if the method returns a single value nil you probably do not get away without assigning that single value to a variable and go from there. Or you test one of the array elements only for nil. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/