From: Emmanuel Touzery Date: 2003-06-03T16:35:11+09:00 Subject: Re: case of sub! not working > Hi, > > In message "Re: case of sub! not working" > on 03/06/03, Ian Macdonald writes: > > |> ENV is not exactly a Hash, but a singleton that behaves kinda like one. > |> Apparently, one difference is that ENV[key] returns a copy of the value. > |> (In hash.c, you can verify this by seeing that rb_f_getenv() calls > |> rb_str_new2 or rb_tainted_str_new2 to generate the return value.) > | > |Thanks for the explanation. This definitely violates the principle of > |least surprise, however, and I consider it a bug. At the very least, it > |should go into the documentation, including the FAQ. > > Never say that. You had two assumptions > > * sub! to modify the receiver in-place > > * when you modify the string from ENV in-place, the value of the > environment variable changes automagically. > > The former assumption is valid, the latter is not. And it costs very > much to satisfy your expectation. > > But I agree with putting it in the FAQ, for people fall into the same > trap. how about making the interpreter running a $ENV.freeze at the beginning of the program? if the variable can't be modified (somehow), it'd be more intuitive if it's read-only, or do i miss something? emmanuel