diff options
author | Burdette Lamar <BurdetteLamar@Yahoo.com> | 2021-09-10 17:21:21 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-10 17:21:21 -0500 |
commit | 967b9743faac0b55a3d8deb176a08fdff449bba8 (patch) | |
tree | ea435619ace589f43b3ed524226b3883eb590f37 /enum.c | |
parent | c09f8e56bc28227aaa1c00d1d6d93e69b322fb41 (diff) |
Enhanced RDoc for Enumerable (#4808)
#to_a
#to_h
#inject
Notes
Notes:
Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
Diffstat (limited to 'enum.c')
-rw-r--r-- | enum.c | 47 |
1 files changed, 21 insertions, 26 deletions
@@ -700,16 +700,13 @@ enum_flat_map(VALUE obj) /* * call-seq: - * enum.to_a(*args) -> array - * enum.entries(*args) -> array + * to_a -> array * - * Returns an array containing the items in <i>enum</i>. + * Returns an array containing the items in +self+: * - * (1..7).to_a #=> [1, 2, 3, 4, 5, 6, 7] - * { 'a'=>1, 'b'=>2, 'c'=>3 }.to_a #=> [["a", 1], ["b", 2], ["c", 3]] + * (0..4).to_a # => [0, 1, 2, 3, 4] * - * require 'prime' - * Prime.entries 10 #=> [2, 3, 5, 7] + * Enumerable#entries is an alias for Enumerable#to_a. */ static VALUE enum_to_a(int argc, VALUE *argv, VALUE obj) @@ -749,20 +746,23 @@ enum_to_h_ii(RB_BLOCK_CALL_FUNC_ARGLIST(i, hash)) /* * call-seq: - * enum.to_h(*args) -> hash - * enum.to_h(*args) {...} -> hash + * to_h -> hash + * to_h {|element| ... } -> hash * - * Returns the result of interpreting <i>enum</i> as a list of - * <tt>[key, value]</tt> pairs. + * When +self+ consists of 2-element arrays, + * returns a hash each of whose entries is the key-value pair + * formed from one of those arrays: * - * %i[hello world].each_with_index.to_h - * # => {:hello => 0, :world => 1} + * [[:foo, 0], [:bar, 1], [:baz, 2]].to_h # => {:foo=>0, :bar=>1, :baz=>2} * - * If a block is given, the results of the block on each element of - * the enum will be used as pairs. + * When a block is given, the block is called with each element of +self+; + * the block should return a 2-element array which becomes a key-value pair + * in the returned hash: * - * (1..5).to_h {|x| [x, x ** 2]} - * #=> {1=>1, 2=>4, 3=>9, 4=>16, 5=>25} + * (0..3).to_h {|i| [i, i ** 2]} # => {0=>0, 1=>1, 2=>4, 3=>9} + * + * Raises an exception if an element of +self+ is not a 2-element array, + * and a block is not passed. */ static VALUE @@ -871,14 +871,10 @@ ary_inject_op(VALUE ary, VALUE init, VALUE op) /* * call-seq: - * enum.inject(initial, sym) -> obj - * enum.inject(sym) -> obj - * enum.inject(initial) { |memo, obj| block } -> obj - * enum.inject { |memo, obj| block } -> obj - * enum.reduce(initial, sym) -> obj - * enum.reduce(sym) -> obj - * enum.reduce(initial) { |memo, obj| block } -> obj - * enum.reduce { |memo, obj| block } -> obj + * inject(symbol) -> obj + * inject(initial_operand, symbol) -> obj + * inject {|memo, element| ... } -> obj + * inject(initial_operand) {|memo, element| ... } -> obj * * Combines all elements of <i>enum</i> by applying a binary * operation, specified by a block or a symbol that names a @@ -913,7 +909,6 @@ ary_inject_op(VALUE ary, VALUE init, VALUE op) * memo.length > word.length ? memo : word * end * longest #=> "sheep" - * */ static VALUE enum_inject(int argc, VALUE *argv, VALUE obj) |