From 85070b5e5679221be0f44ce1886be99432d53dd0 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 28 Aug 2008 22:36:10 -0700 Subject: Date#freeze bug doesn't affect Ruby 1.9 --- .../lib/active_support/core_ext/date/behavior.rb | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/date/behavior.rb b/activesupport/lib/active_support/core_ext/date/behavior.rb index 50c77867f8..bd378eb375 100644 --- a/activesupport/lib/active_support/core_ext/date/behavior.rb +++ b/activesupport/lib/active_support/core_ext/date/behavior.rb @@ -21,15 +21,19 @@ module ActiveSupport #:nodoc: # # Ruby 1.9 uses a preinitialized instance variable so it's unaffected. # This hack is as close as we can get to feature detection: - if (Date.today.freeze.inspect rescue false) - def freeze #:nodoc: - self.class.private_instance_methods(false).each do |m| - if m.to_s =~ /\A__\d+__\Z/ - instance_variable_set(:"@#{m}", [send(m)]) + begin + ::Date.today.freeze.jd + rescue => frozen_object_error + if frozen_object_error.message =~ /frozen/ + def freeze #:nodoc: + self.class.private_instance_methods(false).each do |m| + if m.to_s =~ /\A__\d+__\Z/ + instance_variable_set(:"@#{m}", [send(m)]) + end end - end - super + super + end end end end -- cgit v1.2.3