File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -3037,6 +3037,23 @@ condition](#safe-assignment-in-condition).
30373037 end
30383038 ```
30393039
3040+ * <a name="dont-abuse-gsub"></a>
3041+ Don't use `String#gsub` in scenarios in which you can use a faster more specialized alternative.
3042+ <sup>[[link](#dont-abuse-gsub)]</sup>
3043+
3044+ ```Ruby
3045+ url = 'http://example.com'
3046+ str = 'lisp-case-rules'
3047+
3048+ # bad
3049+ url.gsub("http://", "https://")
3050+ str.gsub("-", "_")
3051+
3052+ # good
3053+ url.sub("http://", "https://")
3054+ str.tr("-", "_")
3055+ ```
3056+
30403057* <a name="heredocs"></a>
30413058 When using heredocs for multi-line strings keep in mind the fact that they
30423059 preserve leading whitespace. It's a good practice to employ some margin based
You can’t perform that action at this time.
0 commit comments