lines = File.readlines("new text document.txt")
lines_count = lines.size
text = lines.join
no_of_chars = text.length
puts "number of lines: #{lines_count}"
puts "number of chars: #{no_of_chars}"
Hello my objective is to count the number of chars in the text document. What I do not understand is why is there a need to lines.join
? And what is the program doing when you lines.join
? Because when I puts lines
or puts lines.join
the program prints out the exact same thing. Therefore what I did (and what I think is correct) is
no_of_chars = lines.length
which is obviously wrong since by doing that the no_of_char
will result in an output that is same as number of lines.