- 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.
- Python編程自學(xué)手冊(cè)
- Instant Testing with CasperJS
- FreeSWITCH 1.8
- WebAssembly實(shí)戰(zhàn)
- Network Automation Cookbook
- jQuery從入門(mén)到精通 (軟件開(kāi)發(fā)視頻大講堂)
- 老“碼”識(shí)途
- Learning Python Design Patterns(Second Edition)
- Raspberry Pi 2 Server Essentials
- SQL Server 2016 從入門(mén)到實(shí)戰(zhàn)(視頻教學(xué)版)
- 從0到1:HTML5 Canvas動(dòng)畫(huà)開(kāi)發(fā)
- Python函數(shù)式編程(第2版)
- ASP.NET求職寶典
- Groovy 2 Cookbook
- Swift High Performance