Why doesn't the Array pop method have an exclamation mark?

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!?

+5
source share
3 answers

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.

+11
source

" , , , . (...) , , , . : , , . mutating ( Array.fill), , (sic)."

( Ruby, Flanagan & Matsumoto, . 180)

exit exit! ( ; exit! at_exit.)

+2

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 !.

+1
source

All Articles