3 ms·
In Ruby, the "?" is optional and used to indicate you are calling a function/method which returns a boolean. The "!" is actually part of the function/method's
by ralmidani 9y ago
In Ruby, the "?" is optional and used to indicate you are calling a function/method which returns a boolean.
The "!" is actually part of the function/method's name. When you want to sort an array, for example, you can either say "sorted_array = array.sort" or you can sort in-place with "array.sort!". So the exclamation distinguishes between the two methods and warns you are performing a destructive operation.