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.
Stated where?
putshas 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.