- Comprehensive Ruby Programming
- Jordan Hudgens
- 143字
- 2021-07-02 21:13:27
Adding a bang
Now I'm going to show you the difference between gsub and gsub!.
Going back to the program, if you print the str variable out after running through the substitution process, the output will still be "The quick brown fox jumped over the quick dog" because the gsub method did not change the variable. On the other hand, if you use gsub!, and then print the value of str, you can see that the str variable now has the "The slow brown fox jumped over the slow dog" value:

This gsub! call can be particularly useful when you want to permanently change the value of the variable. However, you need to be careful, especially when working with legacy systems, because you don't want to accidentally make a permanent change to someone else's variable in case they are expecting a specific value.
- 高效微控制器C語言編程
- Java Web及其框架技術
- Apache Spark 2 for Beginners
- 匯編語言程序設計(第2版)
- Mastering JavaScript Design Patterns(Second Edition)
- BeagleBone Black Cookbook
- HTML5 APP開發從入門到精通(微課精編版)
- The Professional ScrumMaster’s Handbook
- C# Multithreaded and Parallel Programming
- Domain-Driven Design in PHP
- JSP程序設計實例教程(第2版)
- GitHub入門與實踐
- Instant jQuery Boilerplate for Plugins
- Mudbox 2013 Cookbook
- WordPress Search Engine Optimization(Second Edition)