diff options
author | BurdetteLamar <[email protected]> | 2025-03-31 07:50:10 -0500 |
---|---|---|
committer | Peter Zhu <[email protected]> | 2025-03-31 14:49:40 -0400 |
commit | 2d9036498e775dbc8a5a9ba42a6ab02f1c43f2ac () | |
tree | 954f1a30ac11a95d76efcd14c2f1cc8d8f240c0f /hash.c | |
parent | 765918d28317be34ec0c688a7742847801804e36 (diff) |
[DOC] Tweaks for Hash doc
Notes: Merged: https://.com/ruby/ruby/pull/13020
-rw-r--r-- | hash.c | 23 |
1 files changed, 12 insertions, 11 deletions
@@ -6899,27 +6899,28 @@ static const rb_data_type_t env_data_type = { }; /* - * A +Hash+ maps each of its unique keys to a specific value. * - * A +Hash+ has certain similarities to an Array, but: - * - An Array index is always an Integer. - * - A +Hash+ key can be (almost) any object. * - * === +Hash+ \Data Syntax * - * The older syntax for +Hash+ data uses the "hash rocket," <tt>=></tt>: * * h = {:foo => 0, :bar => 1, :baz => 2} * h # => {foo: 0, bar: 1, baz: 2} * - * Alternatively, but only for a +Hash+ key that's a Symbol, * you can use a newer JSON-style syntax, - * where each bareword becomes a Symbol: * * h = {foo: 0, bar: 1, baz: 2} * h # => {foo: 0, bar: 1, baz: 2} * - * You can also use a String in place of a bareword: * * h = {'foo': 0, 'bar': 1, 'baz': 2} * h # => {foo: 0, bar: 1, baz: 2} @@ -6930,12 +6931,12 @@ static const rb_data_type_t env_data_type = { * h # => {foo: 0, bar: 1, baz: 2} * * But it's an error to try the JSON-style syntax - * for a key that's not a bareword or a String: * * # Raises SyntaxError (syntax error, unexpected ':', expecting =>): * h = {0: 'zero'} * - * +Hash+ value can be omitted, meaning that value will be fetched from the context * by the name of the key: * * x = 0 |