From: Lloyd Linklater Date: 2008-10-01T22:04:43+09:00 Subject: Re: Newbie question- Return method Patrick Doyle wrote: > The word "return" is a reserved word in ruby, just like the words > "def", "if", "while", etc... > > "return" is used in a method to exit the method and to return the > given value to the caller. In principal, you could write > > def compute_square(x) > return x*x > end > > ...although The Ruby Way(tm) would be to simply write: > > def compute_square(x) > x*x > end > > since, by the definition of the language, the return value of a method > is (99.99% of the time) the last expression computed in the method. > You can use it to pick what you want returned if it is not the last thing in the method. e.g. def myMethod s d = 'foo' s.upcase! end p myMethod("hiya") => "HIYA" However def myMethod s d = "foo" s.upcase! return d end p myMethod("hiya") => "foo" -- Posted via http://www.ruby-forum.com/.