[DOC] Improve array.rb documentation (#12340)

* Fix grammar errors, typos, and improve readability of array.rb

* [DOC] Remove an extra space

---------

Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
This commit is contained in:
Alex Rocha 2024-12-13 10:27:20 -08:00 committed by GitHub
parent a5f3a01375
commit 89c8d6487c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
Notes: git 2024-12-13 18:27:39 +00:00
Merged-By: k0kubun <takashikkbn@gmail.com>

View File

@ -3,8 +3,8 @@ class Array
# shuffle!(random: Random) -> self # shuffle!(random: Random) -> self
# #
# Shuffles all elements in +self+ into a random order, # Shuffles all elements in +self+ into a random order,
# as selected by the object given by keyword argument +random+; # as selected by the object given by the keyword argument +random+.
# returns +self+: # Returns +self+:
# #
# a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] # a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
# a.shuffle! # => [5, 3, 8, 7, 6, 1, 9, 4, 2, 0] # a.shuffle! # => [5, 3, 8, 7, 6, 1, 9, 4, 2, 0]
@ -16,7 +16,7 @@ class Array
# a.shuffle! # => [1, 0, 0, 1, 1, 0, 1, 0, 0, 1] # a.shuffle! # => [1, 0, 0, 1, 1, 0, 1, 0, 0, 1]
# a.shuffle! # => [0, 1, 0, 1, 1, 0, 1, 0, 1, 0] # a.shuffle! # => [0, 1, 0, 1, 1, 0, 1, 0, 1, 0]
# #
# The object given with keyword argument +random+ is used as the random number generator. # The object given with the keyword argument +random+ is used as the random number generator.
# #
# Related: see {Methods for Assigning}[rdoc-ref:Array@Methods+for+Assigning]. # Related: see {Methods for Assigning}[rdoc-ref:Array@Methods+for+Assigning].
def shuffle!(random: Random) def shuffle!(random: Random)
@ -27,7 +27,7 @@ class Array
# shuffle(random: Random) -> new_array # shuffle(random: Random) -> new_array
# #
# Returns a new array containing all elements from +self+ in a random order, # Returns a new array containing all elements from +self+ in a random order,
# as selected by the object given by keyword argument +random+: # as selected by the object given by the keyword argument +random+:
# #
# a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] # a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
# a.shuffle # => [0, 8, 1, 9, 6, 3, 4, 7, 2, 5] # a.shuffle # => [0, 8, 1, 9, 6, 3, 4, 7, 2, 5]
@ -39,7 +39,7 @@ class Array
# a.shuffle # => [1, 0, 1, 1, 0, 0, 1, 0, 0, 1] # a.shuffle # => [1, 0, 1, 1, 0, 0, 1, 0, 0, 1]
# a.shuffle # => [1, 1, 0, 0, 0, 1, 1, 0, 0, 1] # a.shuffle # => [1, 1, 0, 0, 0, 1, 1, 0, 0, 1]
# #
# The object given with keyword argument +random+ is used as the random number generator. # The object given with the keyword argument +random+ is used as the random number generator.
# #
# Related: see {Methods for Fetching}[rdoc-ref:Array@Methods+for+Fetching]. # Related: see {Methods for Fetching}[rdoc-ref:Array@Methods+for+Fetching].
def shuffle(random: Random) def shuffle(random: Random)
@ -51,7 +51,7 @@ class Array
# sample(count, random: Random) -> new_ary # sample(count, random: Random) -> new_ary
# #
# Returns random elements from +self+, # Returns random elements from +self+,
# as selected by the object given by keyword argument +random+. # as selected by the object given by the keyword argument +random+.
# #
# With no argument +count+ given, returns one random element from +self+: # With no argument +count+ given, returns one random element from +self+:
# #
@ -63,8 +63,7 @@ class Array
# #
# [].sample # => nil # [].sample # => nil
# #
# # With a non-negative numeric argument +count+ given,
# With non-negative numeric argument +count+ given,
# returns a new array containing +count+ random elements from +self+: # returns a new array containing +count+ random elements from +self+:
# #
# a.sample(3) # => [8, 9, 2] # a.sample(3) # => [8, 9, 2]
@ -86,7 +85,7 @@ class Array
# #
# a.sample(50) # => [6, 4, 1, 8, 5, 9, 0, 2, 3, 7] # a.sample(50) # => [6, 4, 1, 8, 5, 9, 0, 2, 3, 7]
# #
# The object given with keyword argument +random+ is used as the random number generator: # The object given with the keyword argument +random+ is used as the random number generator:
# #
# a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] # a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# a.sample(random: Random.new(1)) # => 6 # a.sample(random: Random.new(1)) # => 6
@ -119,7 +118,7 @@ class Array
# #
# [].first # => nil # [].first # => nil
# #
# With non-negative integer argument +count+ given, # With a non-negative integer argument +count+ given,
# returns the first +count+ elements (as available) in a new array: # returns the first +count+ elements (as available) in a new array:
# #
# a.first(0) # => [] # a.first(0) # => []
@ -153,8 +152,7 @@ class Array
# a # => [:foo, "bar", 2] # a # => [:foo, "bar", 2]
# [].last # => nil # [].last # => nil
# #
# # With a non-negative integer argument +n+ given,
# With non-negative integer argument +n+ is given,
# returns a new array containing the trailing +n+ elements of +self+, as available: # returns a new array containing the trailing +n+ elements of +self+, as available:
# #
# a = [:foo, 'bar', 2] # a = [:foo, 'bar', 2]
@ -182,8 +180,7 @@ class Array
# fetch_values(*indexes) { |index| ... } -> new_array # fetch_values(*indexes) { |index| ... } -> new_array
# #
# With no block given, returns a new array containing the elements of +self+ # With no block given, returns a new array containing the elements of +self+
# at the offsets given by +indexes+; # at the offsets specified by +indexes+. Each of the +indexes+ must be an
# each of the +indexes+ must be an
# {integer-convertible object}[rdoc-ref:implicit_conversion.rdoc@Integer-Convertible+Objects]: # {integer-convertible object}[rdoc-ref:implicit_conversion.rdoc@Integer-Convertible+Objects]:
# #
# a = [:foo, :bar, :baz] # a = [:foo, :bar, :baz]
@ -199,8 +196,8 @@ class Array
# #
# With a block given, for each index: # With a block given, for each index:
# #
# - If the index in in range, uses an element of +self+ (as above). # - If the index is in range, uses an element of +self+ (as above).
# - Otherwise calls, the block with the index, and uses the block's return value. # - Otherwise, calls the block with the index and uses the block's return value.
# #
# Example: # Example:
# #