Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.40 KB | None | 0 0
  1. file_path = __dir__ + '/data/1.txt'
  2.  
  3. abort 'Файл не найден' unless File.exist?(file_path)
  4.  
  5. lines = File.readlines(file_path, encoding: 'UTF-8')
  6. puts "Всего строк: #{lines.size}"
  7.  
  8. empty_count = lines.count { |line| line == "\n" }
  9. puts "Пустых строк: #{empty_count}"
  10.  
  11. puts "Последние 5 строк: "
  12. puts
  13. lines[-5..-1].each do |line|
  14.   puts line
  15. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement