我正在编辑的 Rails 应用程序的每个文件都显示此警告,missing frozen string literal comment
,我知道这用于保留内存并避免为所有字符串文字重新分配内存,但是是否有必要在 rails 上使用或默认启用?如果是这样,如何在全局范围内启用它?
最佳答案
不,默认情况下它没有启用。
但是,您可以使用 Rubocop 将其附加到您的文件顶部 Rubocop::Cop::Style::FrozenStringLiteralComment .这是一个可自动纠正的警察。
根据Holger Just :
You can actually enable it globally by invoking the ruby interpreter with ruby
--enable=frozen-string-literal
. However, this is usually a bad idea and will break in various subtle ways unless you are very sure that all files in all your gems and dependencies actually expect frozen literals (which is generally not the case)
关于ruby-on-rails - '#frozen_string_literal : true' is really needed in a rails application? ??我需要把它放在每个文件中吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68746900/