Why does it say "nil" at the end of the output for all of my code?


#1

If I print or use puts, then it will have my text and then end the text with "nil". If I use puts, then the nil will be on the next line.

For example:

puts "Examplecode" will return something like:

Examplecode
nil


#2

That's because puts returns nil, and a ruby program seems to return the last statement evaluated (in this case puts).


#3

I'm getting exactly the same, and I don't understand the comment "a ruby program seems to return the last statement evaluated (in this case puts)". Do I ignore the nil comment or is there something wrong with my scripting? Thanks in anticipation.


#4

puts returns nil, and Ruby will display what the last instruction evaluates to. So if your last instruction is a puts, it's perfectly normal to get nil. Just keep in mind that it's not part of the output, that's it.


#5

Thank you for the explanations.