I'm going through a Ruby tutorial, and learned that the code
puts 'start'
puts
puts 'end'
will output three lines, but the following code
puts 'start'
puts []
puts 'end'
will only output two. The stated reason is that [] isn't an object (edit: "doesn't point to anything"), so puts can't do anything with it, but why is that not also true in the first case?
I tried to find an official page about puts to figure this out, and this one was no help.
The stated reason is that [] isn't an object
Stated where?
puts has a special handling for arrays. When you pass it an array, it prints each element on a new line. You pass it an array with zero elements, it prints zero lines.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With