Skip to content

Instantly share code, notes, and snippets.

@xiy
Last active December 19, 2015 07:59
Show Gist options
  • Save xiy/5922482 to your computer and use it in GitHub Desktop.
Save xiy/5922482 to your computer and use it in GitHub Desktop.
#define the empty variable text
text =''
#define the line_count variable as 0.
line_count = 0
#open the text file I am working with, and use the each method to iterate
#each line and place it into the variable 'line'
File.open("text.txt").each do |line|
#add 1 for each line during each iterated line. (Loop until each line is processed?)
line_count += 1
#add each line to the text variable - not sure why this is line, not line_count?!
text << line
end
#print the total count
puts "#{line_count} lines"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment