Skip to content
Browse files

Date#freeze bug doesn't affect Ruby 1.9

  • Loading branch information...
1 parent c94f6ea commit 85070b5e5679221be0f44ce1886be99432d53dd0 @jeremy jeremy committed
Showing with 11 additions and 7 deletions.
  1. +11 −7 activesupport/lib/active_support/core_ext/date/behavior.rb
View
18 activesupport/lib/active_support/core_ext/date/behavior.rb
@@ -21,15 +21,19 @@ def acts_like_date?
#
# 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

1 comment on commit 85070b5

@NZKoz
Ruby on Rails member

Nice

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