Guest User

Untitled

a guest
Apr 22nd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. # our mystery method
  2. def with_timer
  3. t = Time.now
  4. yield
  5. Time.now - t
  6. end
  7.  
  8. # example usage
  9.  
  10. time_to_speak = with_timer {%x[say hello there andrew]}
  11.  
  12.  
  13.  
  14.  
  15. puts "speaking took #{time_to_speak} seconds"
  16.  
  17.  
  18. =begin
  19. Matt....The program computes how long it takes to run the code within the block %x....The only thing I am unsure of is what # the %x is for... Also note that I got rid of the do block to clean it up...
  20. =end
Add Comment
Please, Sign In to add comment