Last active
August 29, 2015 14:13
-
-
Save nori3tsu/23199da3c20bda39b401 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class StopWatch | |
def start | |
@start_time ||= Time.now | |
@stop_time = nil | |
self | |
end | |
def stop | |
@stop_time = Time.now | |
self | |
end | |
def reset | |
@start_time = nil | |
@stop_time = nil | |
self | |
end | |
def elapsed_millis | |
raise "not started." unless @start_time | |
if @stop_time | |
((@stop_time - @start_time) * 1000).to_i | |
else | |
((Time.now - @start_time) * 1000).to_i | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment