[前][次][番号順一覧][スレッド一覧]

ruby-changes:59376

From: BurdetteLamar <ko1@a...>
Date: Sun, 22 Dec 2019 23:53:05 +0900 (JST)
Subject: [ruby-changes:59376] 890c834ec6 (master): Enhancements for ENV doc

https://git.ruby-lang.org/ruby.git/commit/?id=890c834ec6

From 890c834ec6bb03fab4fee6f5b14f99660a64d207 Mon Sep 17 00:00:00 2001
From: BurdetteLamar <burdettelamar@y...>
Date: Mon, 16 Dec 2019 16:58:53 -0600
Subject: Enhancements for ENV doc


diff --git a/hash.c b/hash.c
index 79f69f6..82383e9 100644
--- a/hash.c
+++ b/hash.c
@@ -5217,9 +5217,17 @@ rb_env_size(VALUE ehash, VALUE args, VALUE eobj) https://github.com/ruby/ruby/blob/trunk/hash.c#L5217
  *   ENV.each_key { |name| block } -> ENV
  *   ENV.each_key                  -> Enumerator
  *
- * Yields each environment variable name.
- *
- * An Enumerator is returned if no block is given.
+ * Yields each environment variable name:
+ *   ENV.replace('foo' => '0', 'bar' => '1') # => ENV
+ *   names = []
+ *   ENV.each_key { |name| names.push(name) } # => ENV
+ *   names # => ["bar", "foo"]
+ *
+ * Returns an Enumerator if no block given:
+ *   e = ENV.each_key # => #<Enumerator: {"bar"=>"1", "foo"=>"0"}:each_key>
+ *   names = []
+ *   e.each { |name| names.push(name) } # => ENV
+ *   names # => ["bar", "foo"]
  */
 static VALUE
 env_each_key(VALUE ehash)
@@ -5258,9 +5266,16 @@ env_values(void) https://github.com/ruby/ruby/blob/trunk/hash.c#L5266
  * call-seq:
  *   ENV.values -> Array
  *
- * Returns every environment variable value as an Array
+ * Returns all environment variable values in an Array:
+ *   ENV.replace('foo' => '0', 'bar' => '1')
+ *   ENV.values # => ['1', '0']
+ * The order of the values is OS-dependent.
+ * See {About Ordering}[#class-ENV-label-About+Ordering].
+ *
+ * Returns the empty Array if ENV is empty:
+ *   ENV.clear
+ *   ENV.values # => []
  */
-
 static VALUE
 env_f_values(VALUE _)
 {
@@ -5272,9 +5287,17 @@ env_f_values(VALUE _) https://github.com/ruby/ruby/blob/trunk/hash.c#L5287
  *   ENV.each_value { |value| block } -> ENV
  *   ENV.each_value                   -> Enumerator
  *
- * Yields each environment variable +value+.
- *
- * An Enumerator is returned if no block was given.
+ * Yields each environment variable value:
+ *   ENV.replace('foo' => '0', 'bar' => '1') # => ENV
+ *   values = []
+ *   ENV.each_value { |value| values.push(value) } # => ENV
+ *   values # => ["1", "0"]
+ *
+ * Returns an Enumerator if no block given:
+ *   e = ENV.each_value # => #<Enumerator: {"bar"=>"1", "foo"=>"0"}:each_value>
+ *   values = []
+ *   e.each { |value| values.push(value) } # => ENV
+ *   values # => ["1", "0"]
  */
 static VALUE
 env_each_value(VALUE ehash)
@@ -5297,9 +5320,16 @@ env_each_value(VALUE ehash) https://github.com/ruby/ruby/blob/trunk/hash.c#L5320
  *   ENV.each_pair { |name, value| block } -> ENV
  *   ENV.each_pair                         -> Enumerator
  *
- * Yields each environment variable +name+ and +value+.
+ * Yields each environment variable name and its value as a 2-element Array:
+ *   h = {}
+ *   ENV.each_pair { |name, value| h[name] = value } # => ENV
+ *   h # => {"bar"=>"1", "foo"=>"0"}
  *
- * If no block is given an Enumerator is returned.
+ * Returns an Enumerator if no block given:
+ *   h = {}
+ *   e = ENV.each_pair # => #<Enumerator: {"bar"=>"1", "foo"=>"0"}:each_pair>
+ *   e.each { |name, value| h[name] = value } # => ENV
+ *   h # => {"bar"=>"1", "foo"=>"0"}
  */
 static VALUE
 env_each_pair(VALUE ehash)
@@ -5340,9 +5370,21 @@ env_each_pair(VALUE ehash) https://github.com/ruby/ruby/blob/trunk/hash.c#L5370
  *   ENV.reject! { |name, value| block } -> ENV or nil
  *   ENV.reject!                         -> Enumerator
  *
- * Equivalent to ENV.delete_if but returns +nil+ if no changes were made.
- *
- * Returns an Enumerator if no block was given.
+ * Similar to ENV.delete_if, but returns +nil+ if no changes were made.
+ *
+ * Deletes each environment variable for which the block returns a truthy value,
+ * returning ENV (if any deletions) or +nil+ (if not):
+ *   ENV.replace('foo' => '0', 'bar' => '1', 'baz' => '2')
+ *   ENV.reject! { |name, value| name.start_with?('b') } # => ENV
+ *   ENV # => {"foo"=>"0"}
+ *   ENV.reject! { |name, value| name.start_with?('b') } # => nil
+ *
+ * Returns an Enumerator if no block given:
+ *   ENV.replace('foo' => '0', 'bar' => '1', 'baz' => '2')
+ *   e = ENV.reject! # => #<Enumerator: {"bar"=>"1", "baz"=>"2", "foo"=>"0"}:reject!>
+ *   e.each { |name, value| name.start_with?('b') } # => ENV
+ *   ENV # => {"foo"=>"0"}
+ *   e.each { |name, value| name.start_with?('b') } # => nil
  */
 static VALUE
 env_reject_bang(VALUE ehash)
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]