红宝石 |数组 sort_by!()函数
Array#sort_by!() : sort_by!()是一个 Array 类方法,它返回已排序数组的枚举数。
Syntax: Array.sort_by!()
Parameter: Array
Return: the enumerator for the sorted array.
示例 #1:
Ruby
# Ruby code for sort_by!() method
# declaring array
a = ["abc", "nil", "dog"]
# declaring array
c = ["cat", "efg", "geeks"]
# declaring array
b = ["cow", "coal", "dog"]
arr = [a, b, c]
# sort_by! method example
puts "sort_by!() method form : #{arr.sort_by!()}\n\n"
Ruby
# Ruby code for sort_by!() method
# declaring array
a = ["abc", "nil", "dog"]
# declaring array
c = ["cat", "efg", "geeks"]
# declaring array
b = ["cow", "coal", "dog"]
# sort_by! method example
puts "sort_by!() method form : #{a.sort_by!()}\n\n"
puts "sort_by!() method form : #{b.sort_by!()}\n\n"
puts "sort_by!() method form : #{c.sort_by!()}\n\n"
输出 :
sort_by!() method form : #
示例 #2:
红宝石
# Ruby code for sort_by!() method
# declaring array
a = ["abc", "nil", "dog"]
# declaring array
c = ["cat", "efg", "geeks"]
# declaring array
b = ["cow", "coal", "dog"]
# sort_by! method example
puts "sort_by!() method form : #{a.sort_by!()}\n\n"
puts "sort_by!() method form : #{b.sort_by!()}\n\n"
puts "sort_by!() method form : #{c.sort_by!()}\n\n"
输出 :
sort_by!() method form : #
sort_by!() method form : #
sort_by!() method form : #
注意:这些 Enumerator 输出值可能因系统而异。