Issue #16164 has been reported by burdettelamar / yahoo.com (Burdette Lamar).

----------------------------------------
Bug #16164: ENV.each with block returns ENV object itself, not Hash
https://bugs.ruby-lang.org/issues/16164

* Author: burdettelamar / yahoo.com (Burdette Lamar)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.3p62 (2019-04-16 revision 67580) [x64-mingw32]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
My code:

x = ENV.each { |name, value| }
puts "Return value class: #{x.class}"
puts "Return value is a Hash? #{x.kind_of?(Hash)}"
puts "Return value is actually ENV itself?  #{x.object_id == ENV.object_id}"

Its output:

Return value class: Object
Return value is a Hash? false
Return value is actually ENV itself?  true

I expected a Hash, because the doc says:

each { |name, value| block } вк Hash

There 's some danger here, because if I modify the returned object, I'm actually modifying ENV itself.

I think this is also true for a number of other methods in ENV;  e.g., ENV.delete_if.




-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>