New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Style/RedundantFreeze
stop considering ENV
values as immutable
#10099
Style/RedundantFreeze
stop considering ENV
values as immutable
#10099
Conversation
d4a889e
to
d99aef0
Compare
Very interesting. Is this documented by ruby anywhere? |
d99aef0
to
b737d52
Compare
Not as far as I know. I checked ruby spec (https://github.com/ruby/spec/tree/master/core/env) but couldn't find anything about this. But the documentations states:
Which depending on how you interpret it, suggest that it goes all the way to the actual process env (i.e. |
Thanks for digging into it. It'd probably be useful to document why |
To be honest it surprised me to see it included in the first place, I'm having trouble understanding the assumption here. |
I think the assumption is that ENV works the same as a Hash, when that obviously isn’t the case. That being said, it probably is fine without explicit documentation. |
Ref: rubocop#6784 `ENV["foo"]` returns a mutable string. ```ruby >> ENV["PATH"].frozen? => true >> ENV["PATH"].object_id => 260 >> ENV["PATH"].object_id => 280 ``` As such it's perfectly legitimate to freeze them in a pattern such as: ```ruby PATH = ENV["PATH"].freeze ```
b737d52
to
72daf0c
Compare
More than that, it assumed all the values were already frozen. |
Well you showed they are frozen right? 😆 In any case, thanks for this change! |
No they're not. They are mutable. You just get a new one on each access. |
Why is |
Because I had a brainfart I guess -_- |
Ok, that explains why I didn't understand the initial reasoning... |
Ref: #6784
ENV["foo"]
returns a new mutable string on every call.As such it's perfectly legitimate to freeze them in a pattern such as: