Output and return value

  • Thread starter Amir Ebrahimifard
  • Start date
A

Amir Ebrahimifard

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

Jesús Gabriel y Galán

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,146
Messages
2,570,832
Members
47,374
Latest member
EmeliaBryc

Latest Threads

Top