What is the use of Destructive Method?

Technology CommunityCategory: Ruby on RailsWhat is the use of Destructive Method?
VietMX Staff asked 3 years ago

Distructive methods are used to change the object value permanently by itself using bang (!) operator.

  • sort returns a new array and leaves the original unchanged.
  • sort! returns the same array with the modification.

The ! indicates it’s a destructive method. It will overwrite the current array with the new result and returns it.