Class: Monotonic::Time
- Inherits:
-
Object
- Object
- Monotonic::Time
- Defined in:
- lib/Monotonic/Time.rb
Instance Attribute Summary collapse
-
#seconds_since_boot ⇒ Object
readonly
class << self.
Class Method Summary collapse
Instance Method Summary collapse
- #+(monotonic_time_addend) ⇒ Object
- #-(monotonic_time_subtrahend) ⇒ Object
-
#initialize ⇒ Time
constructor
A new instance of Time.
- #to_s ⇒ Object
- #to_time ⇒ Object
Constructor Details
#initialize ⇒ Time
Returns a new instance of Time.
16 17 18 19 |
# File 'lib/Monotonic/Time.rb', line 16 def initialize @boot_time = Sys::Uptime.boot_time @seconds_since_boot = Process.clock_gettime(Process::CLOCK_MONOTONIC) end |
Instance Attribute Details
#seconds_since_boot ⇒ Object (readonly)
class << self
14 15 16 |
# File 'lib/Monotonic/Time.rb', line 14 def seconds_since_boot @seconds_since_boot end |
Class Method Details
.now ⇒ Object
9 10 11 |
# File 'lib/Monotonic/Time.rb', line 9 def now self.new end |
Instance Method Details
#+(monotonic_time_addend) ⇒ Object
21 22 23 |
# File 'lib/Monotonic/Time.rb', line 21 def +(monotonic_time_addend) @seconds_since_boot + monotonic_time_addend.seconds_since_boot end |
#-(monotonic_time_subtrahend) ⇒ Object
25 26 27 |
# File 'lib/Monotonic/Time.rb', line 25 def -(monotonic_time_subtrahend) @seconds_since_boot - monotonic_time_subtrahend.seconds_since_boot end |
#to_s ⇒ Object
29 30 31 |
# File 'lib/Monotonic/Time.rb', line 29 def to_s "#{@seconds_since_boot} seconds since boot." end |
#to_time ⇒ Object
33 34 35 |
# File 'lib/Monotonic/Time.rb', line 33 def to_time @boot_time + @seconds_since_boot end |