[DOC] Tweaks for Hash::[]

This commit is contained in:
BurdetteLamar 2025-01-03 13:22:29 -06:00 committed by Peter Zhu
parent f349104259
commit 6b2b537e35
Notes: git 2025-01-03 19:57:02 +00:00

24
hash.c
View File

@ -1795,32 +1795,34 @@ static VALUE rb_hash_to_a(VALUE hash);
* Hash[ [*2_element_arrays] ] -> new_hash * Hash[ [*2_element_arrays] ] -> new_hash
* Hash[*objects] -> new_hash * Hash[*objects] -> new_hash
* *
* Returns a new +Hash+ object populated with the given objects, if any. * Returns a new \Hash object populated with the given objects, if any.
* See Hash::new. * See Hash::new.
* *
* With no argument, returns a new empty +Hash+. * With no argument given, returns a new empty hash.
* *
* When the single given argument is a +Hash+, returns a new +Hash+ * With a single argument given that is a hash,
* populated with the entries from the given +Hash+, excluding the * returns a new hash initialized with the entries from +hash+
* default value or proc. * (but not with its +default+ or +default_proc+):
* *
* h = {foo: 0, bar: 1, baz: 2} * h = {foo: 0, bar: 1, baz: 2}
* Hash[h] # => {:foo=>0, :bar=>1, :baz=>2} * Hash[h] # => {:foo=>0, :bar=>1, :baz=>2}
* *
* When the single given argument is an Array of 2-element Arrays, * With a single argument given that is an array of 2-element arrays,
* returns a new +Hash+ object wherein each 2-element array forms a * returns a new hash wherein each given 2-element array forms a
* key-value entry: * key-value entry:
* *
* Hash[ [ [:foo, 0], [:bar, 1] ] ] # => {:foo=>0, :bar=>1} * Hash[ [ [:foo, 0], [:bar, 1] ] ] # => {:foo=>0, :bar=>1}
* *
* When the argument count is an even number; * With an even number of arguments given,
* returns a new +Hash+ object wherein each successive pair of arguments * returns a new hash wherein each successive pair of arguments
* has become a key-value entry: * is a key-value entry:
* *
* Hash[:foo, 0, :bar, 1] # => {:foo=>0, :bar=>1} * Hash[:foo, 0, :bar, 1] # => {:foo=>0, :bar=>1}
* *
* Raises an exception if the argument list does not conform to any * Raises ArgumentError if the argument list does not conform to any
* of the above. * of the above.
*
* See also {Methods for Creating a Hash}[rdoc-ref:Hash@Methods+for+Creating+a+Hash].
*/ */
static VALUE static VALUE