Skip to content

Date#freeze fails when called more than once in 1.8 #1579

Merged
merged 1 commit into from Jun 9, 2011

2 participants

@bradleybuda

The ActiveSupport Date#freeze monkey-patch tries to call Date's metaprogrammed memoization logic every time you call Date#freeze. As a result, you can't do this:

> Date.today.freeze.freeze
TypeError: can't modify frozen object
from rails/activesupport/lib/active_support/core_ext/date/freeze.rb:22:in `instance_variable_set'
from rails/activesupport/lib/active_support/core_ext/date/freeze.rb:22:in `freeze'
from rails/activesupport/lib/active_support/core_ext/date/freeze.rb:20:in `each'
from rails/activesupport/lib/active_support/core_ext/date/freeze.rb:20:in `freeze'
from (irb):2

The fix is simple; check to see if we've already frozen the object and don't run the memoization logic twice. Patch and unit test are attached.

@josevalim josevalim merged commit 0ad2280 into rails:master Jun 9, 2011
@josevalim josevalim merged commit dd3e7a6 into rails:master Jun 9, 2011
@jake3030 jake3030 pushed a commit to jake3030/rails that referenced this pull request Jun 28, 2011
@FooBarWidget FooBarWidget Require mocha >= 0.9.3, older versions don't work anymore [#1579 stat…
…e:resolved]

Signed-off-by: Joshua Peek <josh@joshpeek.com>
a392f34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.