Skip to content

Instantly share code, notes, and snippets.

@shugo
Created September 28, 2017 09:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shugo/f39dc33ed9d48036e18b59723adb4d9e to your computer and use it in GitHub Desktop.
Save shugo/f39dc33ed9d48036e18b59723adb4d9e to your computer and use it in GitHub Desktop.
module M
refine String do
def gsub(*args)
super(*args) {
yield $~
}
end
end
end
p "foo123".gsub(/([a-z]+)([0-9]+)/) { |s|
p s
p $~
$~[2] + $~[1]
}
using M
p "foo123".gsub(/([a-z]+)([0-9]+)/) { |m|
p m
p $~
m[2] + m[1]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment