Project

General

Profile

Actions

Misc #17412

closed

Regexp vs Range: freezing differences

Added by zverok (Victor Shepelev) over 3 years ago. Updated over 3 years ago.

Status:
Closed
Assignee:
-
[ruby-core:101549]

Description

While working on the changelog, I noticed the following in the 3.0:

/foo/.frozen?  # => true 
(1..3).frozen? # => true 

# but...
Regexp.new('foo').frozen? # => false 
# ...whereupon
Range.new(1, 3).frozen?   # => true 

I'd like to understand, what is there a reason for non-literal regexps to not being frozen, and for ranges to be?
Corresponding tickets (#16377 and #15504) doesn't clarify the reasoning:

For the record: Regexp.new should continue to return unfrozen Regexp instance. (@mame (Yusuke Endoh) at #16377#note-7)

and:

I'm for freezing all Ranges, not only Range literals. I hate the idea of freezing only literals because casually mixing frozen and unfrozen objects leads to hard-to-debug bugs that depend upon data flow. (@mame (Yusuke Endoh) at #15504#note-3)

I understand that the matter is probably negligible, but will be very grateful for some explanations.


Related issues 2 (1 open1 closed)

Related to Ruby master - Feature #8948: Frozen regexAssignedEregon (Benoit Daloze)Actions
Related to Ruby master - Feature #17256: Freeze all Regexp objectsClosedmatz (Yukihiro Matsumoto)Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0