[ruby-core:96050] [Ruby master Feature#16377] Regexp literals should be frozen
From:
daniel@...42.com
Date:
2019-12-02 02:41:28 UTC
List:
ruby-core #96050
Issue #16377 has been updated by Dan0042 (Daniel DeLorme). I'm against. There's no point to freezing objects left and right, just to satisfy some feeling that "immutable objects are good". This goes back to the [grand design change of making ruby immutable by default](https://bugs.ruby-lang.org/issues/16153#note-6), and I am firmly in the camp of "no". ---------------------------------------- Feature #16377: Regexp literals should be frozen https://bugs.ruby-lang.org/issues/16377#change-82899 * Author: byroot (Jean Boussier) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- The following script: ```ruby 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 -- https://bugs.ruby-lang.org/ Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>