3 ms·
I really love the Ruby naming conventions around this: `!` indicates mutation. 2.4.1 :001 > a = [4,3,5,1,2] => [4, 3, 5, 1, 2] 2.4.1 :002 > a.sort =>
by Xavdidtheshadow 7y ago
I really love the Ruby naming conventions around this: `!` indicates mutation.
2.4.1 :001 > a = [4,3,5,1,2]
=> [4, 3, 5, 1, 2]
2.4.1 :002 > a.sort
=> [1, 2, 3, 4, 5]
2.4.1 :003 > a
=> [4, 3, 5, 1, 2]
2.4.1 :004 > a.sort!
=> [1, 2, 3, 4, 5]
2.4.1 :005 > a
=> [1, 2, 3, 4, 5]
- kbp 7y agoA method named "method!" means that it's a somehow "unsafe" version of the method "method". A lot of the time it means "destructive version," but if there's no non-destructive version, the destructive one won't have a ! (eg, Array#shift), and sometimes ! means something else (eg, Kernel#exit! is like Kernel#exit, but doesn't run any at_exit code).