Advertisement
SeeWhyAnEyeSee

Threading a clock in Ruby.

Dec 7th, 2014
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.50 KB | None | 0 0
  1. =begin
  2. Status - Bugged
  3. I cannot even picture a solution in my mind. Not even close.
  4. Maybe 'cause I'm new to threading.
  5. =end
  6. clock = Thread.new {
  7. abort_on_exception = true
  8.  
  9. loop do
  10.         hms_time = Time.now.strftime("%I:%M:%S")
  11.         print "\rCurrent time - #{hms_time}"
  12.         sleep 0.5
  13. end
  14.  
  15. }
  16.  
  17. askname = Thread.new {
  18. puts "\nWhat's your name?" #Trying to escape from \r with \n, Doesn't work. :\
  19. name = gets.chomp
  20. puts name + " is a nice name "
  21. }
  22.  
  23. askname.join
  24. clock.join
  25. sleep
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement