Ruby 数组 sort_by!() 函数
Array#sort_by!() : sort_by!() 是一个Array类方法,用于返回排序后的数组的枚举器。
语法: Array.sort_by!()
参数: Array
返回: 排序后的数组的枚举器。
例子 #1 :
# 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"
输出 :
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 : #
注意: 这些枚举器的输出值可能因系统而异。