Is Fixnum's power! method potentially dangerous?

372 views Asked by At

Why is the power! method in Ruby's Fixnum class named with an exclamation mark? By convention, methods that have a name ending in an ! are potentially dangerous (for example, they may modify the instance in some way).

I can appreciate the difference between gsub and gsub! in String, but what's up with power!? It doesn't seem to modify the Fixnum instance or perform any other "dangerous" actions; it just returns the result.

1

There are 1 answers

0
rfunduk On BEST ANSWER

It's just an inconsistency in the API. Nothing to worry about, move along :)

The ! is just a convention for destructive methods, not a rule.