From: dblack@... Date: 2006-07-20T21:01:58+09:00 Subject: Re: return statement where it is usefull ? Hi -- On Thu, 20 Jul 2006, Julian 'Julik' Tarkhanov wrote: > As for your method, why not use a conditional assignment? Array#index returns > nil when the element is not in the > array, so you can get a nil and suppress it with -1. > > def get_server_index(server) > self.servers.index(server) || -1 > end Definitely (and even "self." can be eliminated) -- also, I would guess that the return value is being tested for negativeness, in which case maybe the test could be changed to test for nil, and then the method could be: def get_server_index(server) servers.index(server) end at which point it would probably cease to be necessary. David -- http://www.rubypowerandlight.com => Ruby/Rails training & consultancy http://www.manning.com/black => RUBY FOR RAILS (reviewed on Slashdot, 7/12/2006!) http://dablog.rubypal.com => D[avid ]A[. ]B[lack's][ Web]log dblack@wobblini.net => me