From: Julian 'Julik' Tarkhanov Date: 2006-07-20T20:16:54+09:00 Subject: Re: return statement where it is usefull ? On 20-jul-2006, at 10:40, Une b�vue wrote: > i've the habit (from java ;-)) to put a return statement in a method > like that : > > def get_server_index(server) > if self.servers.include?(server) > return self.servers.index(server) > end > return -1 > end > > in that case, is it usefull ? (i think not) Ruby implicitly returns from the last expression in the method, but if it's inside a condition it might not return. For instance: def foo case bar when "x" 1 when "y" 2 else 3 end end In this case it will return 1, 2 or 3 implicitly. 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