Created
March 26, 2018 08:31
-
-
Save barsbek/ec2f11ca9077647a2e8eea6586e319ad to your computer and use it in GitHub Desktop.
ruby: replace occurrence
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"some string".gsub(pattern, replacement) # every occurrence of pattern is replaced by replacement | |
"other string".gsub(pattern) { |match| replacement } # every match is replaced by return value (replacement) of block | |
"hello".gsub(/./) { |c| "#{c.ord} " } # 104 101 108 108 111 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment