ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: nobu@ruby-lang.org
To: ruby-core@ruby-lang.org
Subject: [ruby-core:95012] [Ruby master Bug#16173] ENV.delete returns nil when name does not exist and block given
Date: Sat, 21 Sep 2019 07:09:29 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-81639.20190921070928.7a1a6fbbd7455985@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-16173.20190920193245@ruby-lang.org

Issue #16173 has been updated by nobu (Nobuyoshi Nakada).


Comparing with `Hash#delete`, it looks that the document is correct and the code is wrong.

```diff
diff --git i/hash.c w/hash.c
index 8b84a14484..7880178dc8 100644
--- i/hash.c
+++ w/hash.c
@@ -4779,7 +4779,7 @@ env_delete_m(VALUE obj, VALUE name)
     VALUE val;
 
     val = env_delete(name);
-    if (NIL_P(val) && rb_block_given_p()) rb_yield(name);
+    if (NIL_P(val) && rb_block_given_p()) val = rb_yield(name);
     return val;
 }
 
diff --git i/test/ruby/test_env.rb w/test/ruby/test_env.rb
index b01c3b12ee..1a7656ea7d 100644
--- i/test/ruby/test_env.rb
+++ w/test/ruby/test_env.rb
@@ -107,6 +107,7 @@
     assert_invalid_env {|v| ENV.delete(v)}
     assert_nil(ENV.delete("TEST"))
     assert_nothing_raised { ENV.delete(PATH_ENV) }
+    assert_equal("NO TEST", ENV.delete("TEST") {|name| "NO "+name})
   end
 
   def test_getenv
```


----------------------------------------
Bug #16173: ENV.delete returns nil when name does not exist and block given
https://bugs.ruby-lang.org/issues/16173#change-81639

* Author: burdettelamar@yahoo.com (Burdette Lamar)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.4p104 (2019-08-28 revision 67798) [x64-mingw32]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Attached diff.txt:

* ENV.delete for nonexistent name and block given:
  * Test enhanced to verify return value is nil.
  * Documentation corrected to say that return value is nil, not value.


---Files--------------------------------
diff.txt (961 Bytes)


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

  parent reply	other threads:[~2019-09-21  7:09 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-16173.20190920193245@ruby-lang.org>
2019-09-20 19:32 ` [ruby-core:95008] [Ruby master Bug#16173] ENV.delete returns nil when name does not exist and block given burdettelamar
2019-09-20 23:10 ` [ruby-core:95009] " XrXr
2019-09-21  7:09 ` nobu [this message]
2019-09-21 15:55 ` [ruby-core:95017] " burdettelamar
2019-09-21 17:11 ` [ruby-core:95019] " burdettelamar
2019-09-22 18:40 ` [ruby-core:95038] " eregontp
2019-09-24 18:31 ` [ruby-core:95063] " burdettelamar
2019-09-24 19:10 ` [ruby-core:95065] " merch-redmine
2019-10-01  3:34 ` [ruby-core:95166] " nobu
2019-10-01 10:27 ` [ruby-core:95170] " nobu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-81639.20190921070928.7a1a6fbbd7455985@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).