There *is* a sort! method. I don't know why it isn't documented.
There is no magic in the ! suffix: it's just an extra character allowed in Ruby method names. sort and sort! are two technically unrelated methods. They could be called sort and destructive_sort, but Ruby uses the ! *convention*. Many built in methods have a related destructive method.
Code:
class Array
def sort
...
end
def sort!
...
end
end
You can find these using:
[].methods.grep /!/
Which gives us all ! methods supported by Array:
["collect!", "compact!", "reject!", "slice!", "map!", "flatten!", "reverse!", "uniq!", "sort!"]
Bookmarks