Class: Time

Inherits:
Object
  • Object
show all
Defined in:
lib/penknife/spec/time_travel.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.freeze(&block) ⇒ Object



10
11
12
# File 'lib/penknife/spec/time_travel.rb', line 10

def freeze(&block)
  travel_to(Time.now, &block)
end

.nowObject



6
7
8
# File 'lib/penknife/spec/time_travel.rb', line 6

def now 
  @now || now_before_time_travel 
end

.travel_to(time = Time.now, &block) ⇒ Object



14
15
16
17
18
19
# File 'lib/penknife/spec/time_travel.rb', line 14

def travel_to(time = Time.now, &block)
  @now = time
  block.call
ensure
  @now = nil
end

Instance Method Details

#now_before_time_travelObject



3
# File 'lib/penknife/spec/time_travel.rb', line 3

alias_method :now_before_time_travel, :now