4 ms·
Don't mind me, just adding the equivalent ruby code for readers to compare: array.sort # returns a new collection array.sort! # sorts in place (Ruby
by drusepth 5y ago
Don't mind me, just adding the equivalent ruby code for readers to compare:
array.sort # returns a new collection
array.sort! # sorts in place
(Ruby convention is to add a ! when methods directly modify the object they're called on.)
- dragonwriter 5y ago> Ruby convention is to add a ! when methods directly modify the object they're called on No, Ruby convention is to add a “!” when there is a “less safe” version of an operation, for which a “more safe” version exists without a “!”. Mutating versions of methods where a nonmutating version also exists are one common example, but not the only one, and mutating methods without a nonmutating counterpart don't get “!”.