------art_7185_16171400.1153389144918
Content-Type: text/plain; charset=WINDOWS-1252; format=flowed
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

return stops execution of a method.

def m
  return [nil]
  p "here"
end
m

See, "here" never gets printed, if you didn't have the return keyword:
def m
  [nil]
  p "here"
end
m
"here" does get printed.

j`ey
http://www.eachmapinject.com

On 7/20/06, Patrick Gundlach <rubyforum / contextgarden.net> wrote:
>
> Hi,
>
> > 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)
>
>
> I think that both cases are usefull: return indicates that you intention
> to return something and you don't do it by accident. It's more for the
> human who reads the code.
>
> (my 0.02 
>
> Patrick
>
> --
> Posted via http://www.ruby-forum.com/.
>
>

------art_7185_16171400.1153389144918--