[Ruby] nil is returned by puts. this means?

less than 1 minute read

puts returns nil, what do you say?

I’ve ignored it until now, but what does this mean when you think about it?

irb(main):001:0> a = "apple"
=> "apple"
irb(main):002:0> puts a
=> nil

If you look at the above, you can see that there is apple in puts, but it is returning nil.

As a premise, “output” and “return value (return value)” are different things.

They don’t mean the same thing.


just display

・```Return value
#### **` Returns the value and terminates the method`**

So, after all, puts is just a display.

Why do you need such a thing? Reference ↑ Just display it and say that it does not change the program itself. It means to eliminate waste.