From: Jay Levitt Date: 2007-10-20T08:25:02+09:00 Subject: Re: Is it always the norm to skip 'return'? On Sat, 20 Oct 2007 00:38:42 +0900, Peter Hickman wrote: > For the simpler methods it does seem to be a waste to put a return in > there however it should be remembered that the "if" also returns a value. So > > def other(number) > if number == 1 then > puts "In the true condition" > "the number was 1" > else > puts "In the false condition" > "it was something else" > end > end > > puts other(21) > > outputs > > > In the false condition > > it was something else > > The implicit return here is for the whole of the if. Which can be quite > a pain to track down :( I think that's not true, and you're mistaking the output of "puts" on the function (which IS nil) for the output of the if statement (which is the output of the branch that's taken). I know I've seen and used the if/else implicit-return idiom, and a quick IRB check (1.8.6 Cygwin) shows: irb(main):001:0> def other(number) irb(main):002:1> if number == 1 irb(main):003:2> "it was one" irb(main):004:2> else irb(main):005:2* "it was not one" irb(main):006:2> end irb(main):007:1> end => nil irb(main):008:0> other(21) => "it was not one" irb(main):009:0> puts other(21) it was not one => nil irb(main):010:0> other(21).inspect => "\"it was not one\"" -- Jay Levitt | Boston, MA | My character doesn't like it when they Faster: jay at jay dot fm | cry or shout or hit. http://www.jay.fm | - Kristoffer