Skip to content

Instantly share code, notes, and snippets.

@robinsloan
Created September 5, 2013 17:14
Show Gist options
  • Save robinsloan/6453194 to your computer and use it in GitHub Desktop.
Save robinsloan/6453194 to your computer and use it in GitHub Desktop.
Ruby gsub with block
# http://batsov.com/articles/2013/08/30/using-gsub-with-a-block/?utm_source=rubyweekly&utm_medium=email
# num will be passed the string '12'
"Apollo 12".gsub(/\d+/) { |num| num.to_i.next }
# => "Apollo 13"
# string yielded to block is always entire match; can't do matched groups at |m1, m2| etc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment