3 module ActiveSupport
#:nodoc:
4 module CoreExtensions
#:nodoc:
7 # Enable more predictable duck-typing on Date-like classes. See
13 # Date memoizes some instance methods using metaprogramming to wrap
14 # the methods with one that caches the result in an instance variable.
16 # If a Date is frozen but the memoized method hasn't been called, the
17 # first call will result in a frozen object error since the memo
18 # instance variable is uninitialized.
20 # Work around by eagerly memoizing before freezing.
22 # Ruby 1.9 uses a preinitialized instance variable so it's unaffected.
23 # This hack is as close as we can get to feature detection:
25 ::Date.today
.freeze
.jd
26 rescue => frozen_object_error
27 if frozen_object_error
.message
=~
/frozen/
29 self.class.private_instance_methods(false).each
do |m
|
30 if m
.to_s
=~
/\A__\d+__\Z/
31 instance_variable_set(:"@#{m}", [send(m
)])