Skip to content

Instantly share code, notes, and snippets.

@valikos
Last active August 29, 2015 14:08
Show Gist options
  • Save valikos/8bb92e25a31c48a0fbea to your computer and use it in GitHub Desktop.
Save valikos/8bb92e25a31c48a0fbea to your computer and use it in GitHub Desktop.
Class implements 'time to live' functionality
require 'singleton'
require 'active_support'
class TimeToLive
include Singleton
attr_reader :start_time
def initialize
@live = true
@start_time = Time.now
end
def time_to_die?
if expired? && alive?
@live = false
raise StandardError.new('Time to die')
end
end
private
def alive?
@live
end
def expired?
(@start_time + expiration_value) < Time.now
end
def expiration_value
2.minutes
end
end
@valikos
Copy link
Author

valikos commented Oct 23, 2014

For fun ^_^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment