Actually, in the code you supplied, the variable line_count is never
incremented, so it stays zero. BTW, it is not necessary in this case to
explicitly keep track of the line count, because Ruby provides the
global variable $. (dollar-period), which holds the line number of the
last line read.
BTW, the same effect which your code would do, could also be achieved by
a single statement:
text = ' ' + IO.read('text.txt')
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.