5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/tins/date_dummy.rb', line 5
def self.included(modul)
class << modul
alias really_today today
remove_method :today rescue nil
def dummy=(value)
if value.respond_to?(:to_str)
value = Date.parse(value.to_str)
elsif value.respond_to?(:to_date)
value = value.to_date
end
@dummy = value
end
def dummy(value = nil)
if value.nil?
if defined?(@dummy)
@dummy
end
else
begin
old_dummy = @dummy
self.dummy = value
yield
ensure
self.dummy = old_dummy
end
end
end
def today
if dummy
dummy.dup
elsif caller.first =~ /`today`/
really_today
else
really_today
end
end
end
super
end
|