mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
07b803e28a
Replace XML-style markup tags in comments with markdown equivalents: - <code>...</code> to `...` (inline code) - <tt>...</tt> to `...` (teletype/monospace) - <i>...</i> to *...* (italics/emphasis) - +...+ to `...` (parameter/variable references) Updated 80+ files across core source, headers, mrbgems, and libraries to use consistent markdown formatting in documentation comments. Handled edge cases including special characters like <=> operators. Co-authored-by: Atlassian Rovo Dev
93 lines
1.7 KiB
Ruby
93 lines
1.7 KiB
Ruby
##
|
|
# Array
|
|
#
|
|
# ISO 15.2.12
|
|
class Array
|
|
##
|
|
# call-seq:
|
|
# array.each {|element| ... } -> self
|
|
# array.each -> Enumerator
|
|
#
|
|
# Calls the given block for each element of `self`
|
|
# and pass the respective element.
|
|
#
|
|
# ISO 15.2.12.5.10
|
|
def each(&block)
|
|
return to_enum :each unless block
|
|
|
|
idx = 0
|
|
while idx < length
|
|
block.call(self[idx])
|
|
idx += 1
|
|
end
|
|
self
|
|
end
|
|
|
|
##
|
|
# call-seq:
|
|
# array.each_index {|index| ... } -> self
|
|
# array.each_index -> Enumerator
|
|
#
|
|
# Calls the given block for each element of `self`
|
|
# and pass the index of the respective element.
|
|
#
|
|
# ISO 15.2.12.5.11
|
|
def each_index(&block)
|
|
return to_enum :each_index unless block
|
|
|
|
idx = 0
|
|
while idx < length
|
|
block.call(idx)
|
|
idx += 1
|
|
end
|
|
self
|
|
end
|
|
|
|
##
|
|
# call-seq:
|
|
# array.collect! {|element| ... } -> self
|
|
# array.collect! -> new_enumerator
|
|
#
|
|
# Calls the given block for each element of `self`
|
|
# and pass the respective element. Each element will
|
|
# be replaced by the resulting values.
|
|
#
|
|
# ISO 15.2.12.5.7
|
|
def collect!(&block)
|
|
return to_enum :collect! unless block
|
|
|
|
idx = 0
|
|
len = size
|
|
while idx < len
|
|
self[idx] = block.call(self[idx])
|
|
idx += 1
|
|
end
|
|
self
|
|
end
|
|
|
|
##
|
|
# call-seq:
|
|
# array.map! {|element| ... } -> self
|
|
# array.map! -> new_enumerator
|
|
#
|
|
# Alias for collect!
|
|
#
|
|
# ISO 15.2.12.5.20
|
|
alias map! collect!
|
|
|
|
##
|
|
# call-seq:
|
|
# array.sort -> new_array
|
|
# array.sort {|a, b| ... } -> new_array
|
|
#
|
|
# Returns a new Array whose elements are those from `self`, sorted.
|
|
def sort(&block)
|
|
self.dup.sort!(&block)
|
|
end
|
|
|
|
##
|
|
# Array is enumerable
|
|
# ISO 15.2.12.3
|
|
include Enumerable
|
|
end
|