Sha256: ffbb9d4440d544de26c8c8245ff03d9a59a8cf7a8f8804d7f98fa95550788f9b
Contents?: true
Size: 499 Bytes
Versions: 3
Compression:
Stored size: 499 Bytes
Contents
require 'time' module Timewarp def self.freeze(time, &block) frozen_time = time.is_a?(String) ? Time.parse(time) : time control_timeline proc {frozen_time}, &block end def self.control_timeline(timeline_proc) (class <<Time; self; end).class_eval do alias original_now now define_method(:now) { timeline_proc.call } end yield ensure (class <<Time; self; end).class_eval do alias now original_now remove_method :original_now end end end
Version data entries
3 entries across 3 versions & 1 rubygems