Output and return value

Hi
What is difference between “output” and “return value”? for example when
we executed “puts 1+1” ruby outputs 2 and return nil.

On Thu, Aug 5, 2010 at 11:15 AM, Amir E. [email protected]
wrote:

Hi
What is difference between “output” and “return value”? for example when
we executed “puts 1+1” ruby outputs 2 and return nil.

Return value is what a method gives back as a result:

a = method_call(parameters)

a will contain the return value of the method “method_call”

Output, I guess, is referring to showing things in the standard output
device, for example a console. The method “puts”, will write the
parameters you pass to it to the console.

Every method in Ruby returns something, apart from doing its internal
job. In the case of “puts”, after showing things to the console, will
return nil. So if you do:

a = puts(“something”)

the word something will appear in the console and the value nil will
be returned and assigned to the variable a.

Jesus.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs