Make Time#utc and #localtime raise RuntimeError when the object is frozen #4657
+21
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a fix for #4655 that replicates the MRI behaviour of frozen
Time
objects.It adds three tests to
spec/ruby/core/time
that cover the MRI behaviour of frozenTime
objects – I've tried to match the style of the existing tests and copied tests for the same behaviour inArray
. I hope it looks ok.The actual fix is very simple, in
#utc
and #localtimeI've added a check that will throw a
RuntimeError` when the instance is frozen.There are two additional public methods that mutate
Time
objects, but they're not Ruby methods, and I'm unsure about whether or not they should throw errors:RubyTime#updateCal(DateTime)
RubyTime#setDateTime(DateTime)
They also seem to be duplicates of each other, an neither has been touched in 10 years.
Should they be changed to throw the same error, or how is frozen-ness handled when objects are changed from Java code?