I thought that by convention, only methods with an exclamation mark changed the object.
> array = [1, 2, 3] => [1, 2, 3] > array.pop => 3 > array => [1, 2]
Why is the method Array popnot called pop!?
Array
pop
pop!
This is not entirely correct.
From the Ruby Style Guide
The names of potentially dangerous methods (i.e. methods that change themselves or arguments, exit (do not start finalizers such as exit), etc.) must end with an exclamation mark if there is a safe version of this dangerous method .
And the name of the pop method tells exactly what it does, so there is no need to sign it with an exclamation mark.
" , , , . (...) , , , . : , , . mutating ( Array.fill), , (sic)."
Array.fill
( Ruby, Flanagan & Matsumoto, . 180)
exit exit! ( ; exit! at_exit.)
exit
exit!
This convention is still valid, but it popis a well-known method from all implementations of the stack, if you are popsomething from the stack, you delete it effectively.
This is just general knowledge in data structures, rubies just missed adding a sign to it !.
!