Guest User

Untitled

a guest
Mar 24th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. [RUBY CODE]
  2. #!/usr/local/bin/ruby
  3.  
  4. def file_contents(file)
  5. File.open(file, 'r') do |f|
  6. f.each_line do |line|
  7. return line
  8. end
  9. end
  10. end
  11.  
  12. @hash = {}
  13. def populate_and_sort_hash
  14. Dir.entries('.').each do |f|
  15. next if !f.match(/(a|b|c|d|e).txt/)
  16. @hash[f] = file_contents(f) if !File.directory? f
  17. end
  18. puts @hash.sort_by{|k,v| v}
  19. end
  20.  
  21. populate_and_sort_hash
  22.  
  23.  
  24. [OUTPUT]
  25. aguevara@anthony ~/Documents/Bash/Temp $ ruby Test.rb
  26. d.txt
  27. Mar 05 13:00
  28. b.txt
  29. Mar 08 18:00
  30. c.txt
  31. Mar 10 20:00
  32. e.txt
  33. Mar 12 14:00
  34. a.txt
  35. Mar 15 19:15
Add Comment
Please, Sign In to add comment