How to count characters in Ruby

#-----------------------------------------------
# Counting Lines and Characters
#-----------------------------------------------

file= 'FILE PATH HERE'

=begin
Use File to implement the readlines method to read an entire file into an array line by line.
=end

lines = File.readlines(file)

#count the lines
line_count = lines.size 

#join them all into a single string
text = lines.join 

total_characters = text.length

puts "#{line_count} lines"
puts "#{total_characters} characters"

Ruby: Using File to implement the Readlines method to read an entire file into an array line-by-line

=begin
Using File to implement the readlines method to read an entire file into an array line by line.
=end

file= 'FILE PATH HERE'

lines = File.readlines(file)
line_count = lines.size #count the lines
text = lines.join #join them all into a single string

puts "#{line_count} lines"

How to load text files and count lines with Ruby

#-----------------------------------------------
# How to load text files and count lines
#-----------------------------------------------

file= 'FILE PATH HERE'

line_count = 0 # initialize line_count to store the count

=begin
Open the file and iterate over each line while incrementing line_count by 1 each time
=end

File.open(file).each { |line| 
line_count += 1 

}
puts line_count # Print the total to the screen