From: Tito Ciuro Date: 2007-10-20T12:30:13+09:00 Subject: Re: Is it always the norm to skip 'return'? --Apple-Mail-1--204554042 Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Hi Ben and everyone who has replied, Makes sense. Thanks for the input. I understand better now when the usage of 'return'. I appreciate your help. Regards, -- Tito On Oct 19, 2007, at 7:27 PM, Ben Giddings wrote: > On Oct 19, 2007, at 15:05, bbiker wrote: >> The only time you need to implicitly use 'return' is when you want >> the >> value of a variable that was processed prior to the last statement. >> >> for example: >> >> y = some_method(alpha, beta) >> >> do_some_cleanup before returning >> >> return y > > Actually, I'd say the only reason you should use return in a method > is when you want to jump out of a method with a value and stop doing > anything else, i.e. > > def foo(arg) > arg.each do |e| > if e.meets_some_condition? > return e.text > end > end > > "Not found" > end > > The advantage of only using "return" when you want to return > prematurely is that it clues people into the fact that you're > exiting prematurely. Otherwise you know that the method always > returns the value of the last expression you evaluate. > > Ben > > --Apple-Mail-1--204554042--