[DOC] Tweaks for Array doc

This commit is contained in:
BurdetteLamar 2025-01-02 13:31:05 -06:00 committed by Peter Zhu
parent fa0478d355
commit f349104259
Notes: git 2025-01-03 16:43:12 +00:00
2 changed files with 21 additions and 21 deletions

40
array.c
View File

@ -1809,7 +1809,7 @@ static VALUE rb_ary_aref2(VALUE ary, VALUE b, VALUE e);
* If +index+ is out of range, returns +nil+. * If +index+ is out of range, returns +nil+.
* *
* When two Integer arguments +start+ and +length+ are given, * When two Integer arguments +start+ and +length+ are given,
* returns a new +Array+ of size +length+ containing successive elements beginning at offset +start+: * returns a new array of size +length+ containing successive elements beginning at offset +start+:
* *
* a = [:foo, 'bar', 2] * a = [:foo, 'bar', 2]
* a[0, 2] # => [:foo, "bar"] * a[0, 2] # => [:foo, "bar"]
@ -1824,7 +1824,7 @@ static VALUE rb_ary_aref2(VALUE ary, VALUE b, VALUE e);
* a[2, 2] # => [2] * a[2, 2] # => [2]
* *
* If <tt>start == self.size</tt> and <tt>length >= 0</tt>, * If <tt>start == self.size</tt> and <tt>length >= 0</tt>,
* returns a new empty +Array+. * returns a new empty array.
* *
* If +length+ is negative, returns +nil+. * If +length+ is negative, returns +nil+.
* *
@ -1836,7 +1836,7 @@ static VALUE rb_ary_aref2(VALUE ary, VALUE b, VALUE e);
* a[0..1] # => [:foo, "bar"] * a[0..1] # => [:foo, "bar"]
* a[1..2] # => ["bar", 2] * a[1..2] # => ["bar", 2]
* *
* Special case: If <tt>range.start == a.size</tt>, returns a new empty +Array+. * Special case: If <tt>range.start == a.size</tt>, returns a new empty array.
* *
* If <tt>range.end</tt> is negative, calculates the end index from the end: * If <tt>range.end</tt> is negative, calculates the end index from the end:
* *
@ -1860,7 +1860,7 @@ static VALUE rb_ary_aref2(VALUE ary, VALUE b, VALUE e);
* a[4..-1] # => nil * a[4..-1] # => nil
* *
* When a single Enumerator::ArithmeticSequence argument +aseq+ is given, * When a single Enumerator::ArithmeticSequence argument +aseq+ is given,
* returns an +Array+ of elements corresponding to the indexes produced by * returns an array of elements corresponding to the indexes produced by
* the sequence. * the sequence.
* *
* a = ['--', 'data1', '--', 'data2', '--', 'data3'] * a = ['--', 'data1', '--', 'data2', '--', 'data3']
@ -2402,7 +2402,7 @@ ary_aset_by_rb_ary_splice(VALUE ary, long beg, long len, VALUE val)
* a[-1] = 'two' # => "two" * a[-1] = 'two' # => "two"
* a # => [:foo, "bar", "two"] * a # => [:foo, "bar", "two"]
* *
* When Integer arguments +start+ and +length+ are given and +object+ is not an +Array+, * When Integer arguments +start+ and +length+ are given and +object+ is not an array,
* removes <tt>length - 1</tt> elements beginning at offset +start+, * removes <tt>length - 1</tt> elements beginning at offset +start+,
* and assigns +object+ at offset +start+: * and assigns +object+ at offset +start+:
* *
@ -2437,7 +2437,7 @@ ary_aset_by_rb_ary_splice(VALUE ary, long beg, long len, VALUE val)
* a[1, 5] = 'foo' # => "foo" * a[1, 5] = 'foo' # => "foo"
* a # => [:foo, "foo"] * a # => [:foo, "foo"]
* *
* When Range argument +range+ is given and +object+ is not an +Array+, * When Range argument +range+ is given and +object+ is not an array,
* removes <tt>length - 1</tt> elements beginning at offset +start+, * removes <tt>length - 1</tt> elements beginning at offset +start+,
* and assigns +object+ at offset +start+: * and assigns +object+ at offset +start+:
* *
@ -3013,7 +3013,7 @@ rb_ary_to_s(VALUE ary)
* call-seq: * call-seq:
* to_a -> self or new_array * to_a -> self or new_array
* *
* When +self+ is an instance of +Array+, returns +self+. * When +self+ is an instance of \Array, returns +self+.
* *
* Otherwise, returns a new array containing the elements of +self+: * Otherwise, returns a new array containing the elements of +self+:
* *
@ -8366,8 +8366,8 @@ rb_ary_deconstruct(VALUE ary)
* *
* == Example Usage * == Example Usage
* *
* In addition to the methods it mixes in through the Enumerable module, the * In addition to the methods it mixes in through the Enumerable module,
* +Array+ class has proprietary methods for accessing, searching and otherwise * class \Array has proprietary methods for accessing, searching and otherwise
* manipulating arrays. * manipulating arrays.
* *
* Some of the more common ones are illustrated below. * Some of the more common ones are illustrated below.
@ -8415,9 +8415,9 @@ rb_ary_deconstruct(VALUE ary)
* *
* arr.drop(3) #=> [4, 5, 6] * arr.drop(3) #=> [4, 5, 6]
* *
* == Obtaining Information about an +Array+ * == Obtaining Information about an \Array
* *
* Arrays keep track of their own length at all times. To query an array * An array keeps track of its own length at all times. To query an array
* about the number of elements it contains, use #length, #count or #size. * about the number of elements it contains, use #length, #count or #size.
* *
* browsers = ['Chrome', 'Firefox', 'Safari', 'Opera', 'IE'] * browsers = ['Chrome', 'Firefox', 'Safari', 'Opera', 'IE']
@ -8432,7 +8432,7 @@ rb_ary_deconstruct(VALUE ary)
* *
* browsers.include?('Konqueror') #=> false * browsers.include?('Konqueror') #=> false
* *
* == Adding Items to Arrays * == Adding Items to an \Array
* *
* Items can be added to the end of an array by using either #push or #<< * Items can be added to the end of an array by using either #push or #<<
* *
@ -8453,7 +8453,7 @@ rb_ary_deconstruct(VALUE ary)
* arr.insert(3, 'orange', 'pear', 'grapefruit') * arr.insert(3, 'orange', 'pear', 'grapefruit')
* #=> [0, 1, 2, "orange", "pear", "grapefruit", "apple", 3, 4, 5, 6] * #=> [0, 1, 2, "orange", "pear", "grapefruit", "apple", 3, 4, 5, 6]
* *
* == Removing Items from an +Array+ * == Removing Items from an \Array
* *
* The method #pop removes the last element in an array and returns it: * The method #pop removes the last element in an array and returns it:
* *
@ -8493,11 +8493,11 @@ rb_ary_deconstruct(VALUE ary)
* arr = [2, 5, 6, 556, 6, 6, 8, 9, 0, 123, 556] * arr = [2, 5, 6, 556, 6, 6, 8, 9, 0, 123, 556]
* arr.uniq #=> [2, 5, 6, 556, 8, 9, 0, 123] * arr.uniq #=> [2, 5, 6, 556, 8, 9, 0, 123]
* *
* == Iterating over Arrays * == Iterating over an \Array
* *
* Like all classes that include the Enumerable module, +Array+ has an each * Like all classes that include the Enumerable module, class \Array has an each
* method, which defines what elements should be iterated over and how. In * method, which defines what elements should be iterated over and how. In
* case of Array's #each, all elements in the +Array+ instance are yielded to * case of Array#each, all elements in +self+ are yielded to
* the supplied block in sequence. * the supplied block in sequence.
* *
* Note that this operation leaves the array unchanged. * Note that this operation leaves the array unchanged.
@ -8524,7 +8524,7 @@ rb_ary_deconstruct(VALUE ary)
* arr #=> [1, 4, 9, 16, 25] * arr #=> [1, 4, 9, 16, 25]
* *
* *
* == Selecting Items from an +Array+ * == Selecting Items from an \Array
* *
* Elements can be selected from an array according to criteria defined in a * Elements can be selected from an array according to criteria defined in a
* block. The selection can happen in a destructive or a non-destructive * block. The selection can happen in a destructive or a non-destructive
@ -8557,13 +8557,13 @@ rb_ary_deconstruct(VALUE ary)
* *
* == What's Here * == What's Here
* *
* First, what's elsewhere. Class +Array+: * First, what's elsewhere. Class \Array:
* *
* - Inherits from {class Object}[rdoc-ref:Object@What-27s+Here]. * - Inherits from {class Object}[rdoc-ref:Object@What-27s+Here].
* - Includes {module Enumerable}[rdoc-ref:Enumerable@What-27s+Here], * - Includes {module Enumerable}[rdoc-ref:Enumerable@What-27s+Here],
* which provides dozens of additional methods. * which provides dozens of additional methods.
* *
* Here, class +Array+ provides methods that are useful for: * Here, class \Array provides methods that are useful for:
* *
* - {Creating an Array}[rdoc-ref:Array@Methods+for+Creating+an+Array] * - {Creating an Array}[rdoc-ref:Array@Methods+for+Creating+an+Array]
* - {Querying}[rdoc-ref:Array@Methods+for+Querying] * - {Querying}[rdoc-ref:Array@Methods+for+Querying]
@ -8576,7 +8576,7 @@ rb_ary_deconstruct(VALUE ary)
* - {Converting}[rdoc-ref:Array@Methods+for+Converting] * - {Converting}[rdoc-ref:Array@Methods+for+Converting]
* - {And more....}[rdoc-ref:Array@Other+Methods] * - {And more....}[rdoc-ref:Array@Other+Methods]
* *
* === Methods for Creating an +Array+ * === Methods for Creating an \Array
* *
* - ::[]: Returns a new array populated with given objects. * - ::[]: Returns a new array populated with given objects.
* - ::new: Returns a new array. * - ::new: Returns a new array.

View File

@ -71,7 +71,7 @@ class Array
# #
# The order of the result array is unrelated to the order of +self+. # The order of the result array is unrelated to the order of +self+.
# #
# Returns a new empty +Array+ if +self+ is empty: # Returns a new empty array if +self+ is empty:
# #
# [].sample(4) # => [] # [].sample(4) # => []
# #