Created
August 10, 2012 04:46
-
-
Save znz/3311132 to your computer and use it in GitHub Desktop.
$1 を使っている String#gsub を置き換えてみるテスト
This file contains 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
% ruby -v gsub.rb | |
ruby 1.8.7 (2011-06-30 patchlevel 352) [x86_64-linux] | |
<a><b><c> | |
% ruby -v gsub.rb | |
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux] | |
<a><b><c> |
This file contains 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
if true | |
class String | |
alias _gsub gsub | |
def gsub(*args, &block) | |
_gsub(*args) do |*block_args| | |
$_match_data = $~ | |
eval("$~ = $_match_data", block.binding) | |
block.call(*block_args) | |
end | |
end | |
end | |
end | |
s = "abc".gsub(/(.)/) do | |
"<#{$1}>" | |
end | |
puts s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment