Skip to content
Browse files

Merge pull request #1579 from bradleybuda/master

Date#freeze fails when called more than once in 1.8
  • Loading branch information...
2 parents 12245a3 + dd3e7a6 commit 0ad228027d4cca2b24a38aa84f6360f2732110d1 @josevalim josevalim committed Jun 8, 2011
View
10 activesupport/lib/active_support/core_ext/date/freeze.rb
@@ -5,7 +5,7 @@
# first call will result in a frozen object error since the memo
# instance variable is uninitialized.
#
-# Work around by eagerly memoizing before freezing.
+# Work around by eagerly memoizing before the first freeze.
#
# Ruby 1.9 uses a preinitialized instance variable so it's unaffected.
# This hack is as close as we can get to feature detection:
@@ -17,9 +17,11 @@
if frozen_object_error.message =~ /frozen/
class Date #:nodoc:
def freeze
- self.class.private_instance_methods(false).each do |m|
- if m.to_s =~ /\A__\d+__\Z/
- instance_variable_set(:"@#{m}", [send(m)])
+ unless frozen?
+ 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
View
6 activesupport/test/core_ext/date_ext_test.rb
@@ -454,4 +454,10 @@ def test_freeze_doesnt_clobber_memoized_instance_methods
Date.today.freeze.inspect
end
end
+
+ def test_can_freeze_twice
+ assert_nothing_raised do
+ Date.today.freeze.freeze
+ end
+ end
end

0 comments on commit 0ad2280

Please sign in to comment.
Something went wrong with that request. Please try again.