Merge pull request #1579 from bradleybuda/master
Date#freeze fails when called more than once in 1.8
This commit is contained in:
commit
0ad228027d
|
@ -5,7 +5,7 @@
|
||||||
# first call will result in a frozen object error since the memo
|
# first call will result in a frozen object error since the memo
|
||||||
# instance variable is uninitialized.
|
# 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.
|
# Ruby 1.9 uses a preinitialized instance variable so it's unaffected.
|
||||||
# This hack is as close as we can get to feature detection:
|
# This hack is as close as we can get to feature detection:
|
||||||
|
@ -17,9 +17,11 @@ if RUBY_VERSION < '1.9'
|
||||||
if frozen_object_error.message =~ /frozen/
|
if frozen_object_error.message =~ /frozen/
|
||||||
class Date #:nodoc:
|
class Date #:nodoc:
|
||||||
def freeze
|
def freeze
|
||||||
self.class.private_instance_methods(false).each do |m|
|
unless frozen?
|
||||||
if m.to_s =~ /\A__\d+__\Z/
|
self.class.private_instance_methods(false).each do |m|
|
||||||
instance_variable_set(:"@#{m}", [send(m)])
|
if m.to_s =~ /\A__\d+__\Z/
|
||||||
|
instance_variable_set(:"@#{m}", [send(m)])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -454,4 +454,10 @@ class DateExtBehaviorTest < Test::Unit::TestCase
|
||||||
Date.today.freeze.inspect
|
Date.today.freeze.inspect
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_can_freeze_twice
|
||||||
|
assert_nothing_raised do
|
||||||
|
Date.today.freeze.freeze
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue