Bug #16192

ENV.update hash values ignored when block given

Added by (Burdette Lamar) 5 months ago. Updated 3 months ago.

Target version:



update(hash) → Hash
update(hash) { |name, old_value, new_value| block } → Hash

Adds the contents of hash to the environment variables. If no block is specified entries with duplicate keys are overwritten, otherwise the value of each duplicate name is determined by calling the block with the key, its value from the environment and its value from the hash.


The attached code shows that the block is called and its returned value assigned even if the name is not a duplicate. So basically this means that when a block is given, the hash values are ignored for all keys.

I had expected that for a non-duplicate name, the block would be ignored, and the hash value assigned.

I'm calling this a Misc, and not a Bug, just in case I'm missing something.


t.rb (179 Bytes) t.rb (Burdette Lamar), 09/30/2019 09:58 PM

Updated by shevegen (Robert A. Heiler) 5 months ago

I can not say whether it is a bug or not, but I believe that either way,
it would be good to mention, in the documentation, which behaviour is to
be expected e. g. for the example you gave:

ENV.update('foo' => 'value_from_hash') { |name, old, new| 'value_from_block' }

If I understood the behaviour correctly then the block has a higher priority than
the (first) argument to .update(). Again, no idea if this is a bug or the
desired behaviour, but I think it would help if the documentation could
specify this and perhaps add a few examples to quickly demonstrate the use of
the method.

(Here is the link I used, if anyone else wants to look at it quickly: )

Updated by nobu (Nobuyoshi Nakada) 5 months ago

  • Description updated (diff)

I think this is a bug, for the same reason as [Bug #16173].

Updated by Eregon (Benoit Daloze) 3 months ago

  • Backport set to 2.5: UNKNOWN, 2.6: UNKNOWN
  • Tracker changed from Misc to Bug

This is a clear bug, I'll merge nobu (Nobuyoshi Nakada)'s patch.
There are already specs for this from, which I'll synchronize to MRI soon.


Updated by nobu (Nobuyoshi Nakada) 3 months ago

  • Status changed from Open to Closed

Applied in changeset git|5e0479f26afe1505afd9014ea96a206a88845828.

ENV.update should not call block on existing keys

[Bug #16192]

Also available in: Atom PDF