From: "Hal E. Fulton" Date: 2003-06-04T04:29:31+09:00 Subject: Re: case of sub! not working ----- Original Message ----- From: "Michael Campbell" To: "ruby-talk ML" Sent: Tuesday, June 03, 2003 8:15 AM Subject: Re: case of sub! not working > > > 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. > > Can someone mention *why* this is like it is? (ENV keys are copies > so modifications are lost.) I'll take a stab at it. I can't promise that what I say is correct. The illusion of ENV being a simple hash is a good one. But remember that when you get/set environment variables, ultimately you are calling getenv/setenv or some equivalent. It's one thing to do an ENV[x] = y, as []= is a method invoked on ENV. We can trap the change and call setenv. But if ENV[x] refers to a string, and I change that string... then ENV itself hasn't changed. In fact, for an in-place change, even the object id of the string hasn't changed. To accomplish something like ENV[x].sub! working intuitively, we would have to monitor every string object referenced by ENV and watch to see when any of them was changed. Perhaps possible but impractical and inefficient. Hal