Given the following code:
File.open('file1.txt', 'r') do |file|
while line = file.gets
puts "** " + line.chomp.reverse + " **"
while line = file gets
x=3 x ==3
In Ruby everything evaluates to truthy or falsey.
There are two falsey things:
Everything else is truthy.
while loop checks for truthiness of
Until it is anything but either
false it loops.
In your example the loop will stop when
nil, meaning, there's no next line.