summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authorBurdette Lamar <BurdetteLamar@Yahoo.com>2019-10-12 19:48:20 -0500
committerNobuyoshi Nakada <nobu@ruby-lang.org>2019-10-13 09:48:20 +0900
commit6a1809e2e1a95c14cfb72701df480e3ebccd4b24 (patch)
tree6bc8e29be54663260a344a8da3df9a170101210c /hash.c
parent6ee2fb5021c4c09b718b88089c83073997d5412f (diff)
Enhance doc for ENV.delete
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/2542
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/hash.c b/hash.c
index d00a09db5b..9b5f978dd9 100644
--- a/hash.c
+++ b/hash.c
@@ -4769,9 +4769,21 @@ env_delete(VALUE name)
* ENV.delete(name) -> value
* ENV.delete(name) { |name| block } -> value
*
- * Deletes the environment variable with +name+ and returns the value of the
- * variable. If a block is given it will be called when the named environment
- * does not exist.
+ * Deletes the environment variable with +name+ if it exists and returns its value:
+ * ENV['foo'] = '0'
+ * ENV.delete('foo') # => '0'
+ * Returns +nil+ if the named environment variable does not exist:
+ * ENV.delete('foo') # => nil
+ * If a block given and the environment variable does not exist,
+ * yields +name+ to the block and returns +nil+:
+ * ENV.delete('foo') { |name| puts name } # => nil
+ * foo
+ * If a block given and the environment variable exists,
+ * deletes the environment variable and returns its value (ignoring the block):
+ * ENV['foo'] = '0'
+ * ENV.delete('foo') { |name| fail 'ignored' } # => "0"
+ * Raises TypeError if +name+ is not a String and cannot be coerced with \#to_str:
+ * ENV.delete(Object.new) # => TypeError raised
*/
static VALUE
env_delete_m(VALUE obj, VALUE name)