One of Ruby’s specifics is the usage of exclamation marks ! (bang) at the end of several method names. Such methods also are called dangerous methods.
Dangerous methods
Methods are called “dangerous”, if they have a “non-dangerous” companion. The ! in the methods name is not meant for stating the method would do dangerous things. It means the method has a little brother, doing something similar.
For example:
language = " Ruby "
# little brother
language.strip # => "Ruby"
language # => " Ruby "
# big brother
language.strip! # => "Ruby"
language # => "Ruby"
Indeed most dangerous methods modify the message receiver. But that does not mean, that each receiver modifying method got a bang in its name. There are many methods without !, which also modify the message receiver:
languages = %w(Ruby Erlang Go)
languages.clear # => []
languages # => []
Prima donna methods
A prima donna is a dramatic opera singer per definition. Balky, self-opinionated men or woman also are called prima donna-ish.
Prima donna Methods are methods having no “little brother”, but are marked with a ! in opposition to the convention.
For example:
# bad
class User
# Prima donna method
def save!
end
end
in contrast to:
# good
class User
def save
end
def save!
end
end
In practice there is rarely the need for implementing 2 methods with almost similar business logic. And that is why dangerous methods (with !) are rarely necessary at all.
Various code linter detect prima donna methods and signal them as a violation of the Ruby style guide.