ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:94908] [Ruby master Bug#16164] ENV.each with block returns ENV object itself, not Hash
       [not found] <redmine.issue-16164.20190911212424@ruby-lang.org>
@ 2019-09-11 21:24 ` burdettelamar
  2019-09-12  3:26 ` [ruby-core:94917] " sawadatsuyoshi
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 4+ messages in thread
From: burdettelamar @ 2019-09-11 21:24 UTC (permalink / raw
  To: ruby-core

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/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [ruby-core:94917] [Ruby master Bug#16164] ENV.each with block returns ENV object itself, not Hash
       [not found] <redmine.issue-16164.20190911212424@ruby-lang.org>
  2019-09-11 21:24 ` [ruby-core:94908] [Ruby master Bug#16164] ENV.each with block returns ENV object itself, not Hash burdettelamar
@ 2019-09-12  3:26 ` sawadatsuyoshi
  2019-09-12  6:47 ` [ruby-core:94919] " shevegen
  2019-09-20 18:50 ` [ruby-core:95007] " burdettelamar
  3 siblings, 0 replies; 4+ messages in thread
From: sawadatsuyoshi @ 2019-09-12  3:26 UTC (permalink / raw
  To: ruby-core

Issue #16164 has been updated by sawa (Tsuyoshi Sawada).


That is a documentation bug.

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

* 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/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [ruby-core:94919] [Ruby master Bug#16164] ENV.each with block returns ENV object itself, not Hash
       [not found] <redmine.issue-16164.20190911212424@ruby-lang.org>
  2019-09-11 21:24 ` [ruby-core:94908] [Ruby master Bug#16164] ENV.each with block returns ENV object itself, not Hash burdettelamar
  2019-09-12  3:26 ` [ruby-core:94917] " sawadatsuyoshi
@ 2019-09-12  6:47 ` shevegen
  2019-09-20 18:50 ` [ruby-core:95007] " burdettelamar
  3 siblings, 0 replies; 4+ messages in thread
From: shevegen @ 2019-09-12  6:47 UTC (permalink / raw
  To: ruby-core

Issue #16164 has been updated by shevegen (Robert A. Heiler).


I remember the old pickaxe having mentioned ENV as a hash-like
object. I guess the documentation could be updated to include
e. g. specifically a .is_a? Hash check too, and explain that
ENV is not completely a "full" Hash.

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

* 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/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [ruby-core:95007] [Ruby master Bug#16164] ENV.each with block returns ENV object itself, not Hash
       [not found] <redmine.issue-16164.20190911212424@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2019-09-12  6:47 ` [ruby-core:94919] " shevegen
@ 2019-09-20 18:50 ` burdettelamar
  3 siblings, 0 replies; 4+ messages in thread
From: burdettelamar @ 2019-09-20 18:50 UTC (permalink / raw
  To: ruby-core

Issue #16164 has been updated by burdettelamar@yahoo.com (Burdette Lamar).

File diff.txt added

I'm attaching a diff that:

* Enhances the test to verify the returned object, which is ENV.
* Corrects the documentation to say that the returned object is ENV, not a Hash.


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

* 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.


---Files--------------------------------
diff.txt (1.17 KB)


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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-09-20 18:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <redmine.issue-16164.20190911212424@ruby-lang.org>
2019-09-11 21:24 ` [ruby-core:94908] [Ruby master Bug#16164] ENV.each with block returns ENV object itself, not Hash burdettelamar
2019-09-12  3:26 ` [ruby-core:94917] " sawadatsuyoshi
2019-09-12  6:47 ` [ruby-core:94919] " shevegen
2019-09-20 18:50 ` [ruby-core:95007] " burdettelamar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).