Home

Ruby Intro

Resources

  1. Ruby Style Guide
  2. Rails Stylde Guide
  3. Modern Resources for Rails 6
  4. Secure Rails
  5. Awesome Rails
  6. Awesome Ruby
  7. Ruby Symbols vs Strings
  8. Rails Performance
  9. Culture Amp Guide - Requires Auth
  10. Culture Amp Testing Guide (Performance) - Requires Auth
  11. Standard - RuboCop Subset
  12. Factory Bot Tutorial

Bang (!) Methods

Ruby methods that modify an object in-place and end in an exclamation mark are known as bang methods. By convention, the bang labels a method as dangerous - specifically, as the dangerous equivalent of a method with the same name but without the bang.

You'll find a number of pairs of methods, one with the bang and one without. Those without the bang perform an action and return a freshly minted object, reflecting the results of the action (capitalizing a string, sorting an array, and so on). The bang versions of the same methods perform the action, but they do so in place: Instead of creating a new object, they transform the original object.

Examples of such pairs of methods include sort/sort! for arrays, upcase/upcase! for strings, chomp/chomp! for strings, and reverse/reverse! for strings and arrays. In each case, if you call the non-bang version of the method on the object, you get a new object. If you call the bang version, you operate in-place on the same object to which you sent the message.

Repository

https://github.com/okeeffed/developer-notes-nextjs/content/ruby/intro

Sections


Related