Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Jun 9, 2011

Conversation

bradleybuda
Copy link
Contributor

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 added a commit that referenced this pull request Jun 9, 2011
Date#freeze fails when called more than once in 1.8
@josevalim josevalim merged commit 0ad2280 into rails:master Jun 9, 2011
@josevalim josevalim merged commit dd3e7a6 into rails:master Jun 9, 2011
jake3030 pushed a commit to jake3030/rails that referenced this pull request Jun 28, 2011
…state:resolved]

Signed-off-by: Joshua Peek <josh@joshpeek.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants