Project

General

Profile

Actions

Feature #16377

closed

Regexp literals should be frozen

Added by byroot (Jean Boussier) about 3 years ago. Updated about 2 years ago.

Status:
Closed
Priority:
Normal
Target version:
[ruby-core:95977]

Description

The following script:

def mutate
  re = /foo/
  state = re.instance_variable_get(:@state)
  re.instance_variable_set(:@state, state.to_i + 1)
  state
end

3.times do
  p mutate
end

Output this:

nil
1
2

IMHO, you shouldn't be able to mutate an unduplicated literal.

GitHub pull request: https://github.com/ruby/ruby/pull/2705


Related issues 1 (1 open0 closed)

Is duplicate of Ruby master - Feature #8948: Frozen regexAssignedmatz (Yukihiro Matsumoto)Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0