> Return means "we are done".
> 
> Sometimes when you write a method (I don't know the jargon used in
> that book, it may be function, or subroutine, or procedure, ...) you
> know somewhere in the middle that _if the code reached that point_ we
> do not need to do anything else. For instance, see this method that
> says where the given number is positive:
> 
>    def is_positive?(n)
>      if n > 0
>        return true
>      end
>      return false
>    end
> 
> That method can be written in different ways, but to depict the
> meaning of return: if n is greater than 0, you already know the
> answer, so in that point you indicate there's no need to execute more
> code, you're ready to give the answer: true. If the execution reaches
> that point, the following executable line "return false" will be
> ignored altogether, execution is halted.
> 
> Return in addition accepts a value to be returned (true/false in the
> example), which is considered to be the _result_ of that method call
> in such case.

  So you are saying that it basically saves the confusion of elsif's and 
it just makes more sense.. in your example you could have easily written

def is_positive?(n)
 if n > 0
       answer= true
    elsif
    n<0
       answer= false
end

 Right? but that just looks sloppy and could really get confusing if i 
had more lines of code.. am i getting it right?

>> def englishNumber number
> 
> <snip>
> 
>> end
> 
> The purpose of that method is to compute and return a _string_, not
> to actually _print_ that string.
> 
>> puts englishNumber(  0)
> 
> Now here you have two calls: first a call to englishNumber(  0), and
> then a call to puts. They are executed in that order, and the string
> returned by the first call is chained into the second call, so puts
> is the one that prints the string.

   so basically when you define a method you are saying that when i call 
this method, i want this done with the thing next to it. So here it is 
saying i want you to run all these checks on the number next to 
"englishNumber"? then it runs each of those tests .. the if statements 
and once one is true to that statement, then it stops there and prints 
out the last line before end?

-- 
Posted via http://www.ruby-forum.com/.