→ The Bang
26 May 2008
I was checking out Ryan Lowe’s save_or_raise project today and stumbled upon this quote:
Ruby methods that end with an exclamation point are a signal that they change the object they operate on.
This is not true. A common misconception.
The Ruby stdlib uses bang methods to identify a more dangerous version of a non-bang method. For example, Hash#merge! is the ‘dangerous’ version of Hash#merge – the former affects the receiver while the latter does not.
Hash#update, the bangless alias for Hash#merge!, illustrates the other side of this idiom. No counterpart, no bang.