-
-
Save tai2/eaa11210a7c5e6d71196f099a936be80 to your computer and use it in GitHub Desktop.
Regexp.last_match in the block of gsub should not be nil
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
class A | |
def initialize | |
@str = 'This is a string' | |
end | |
def method_missing(name, *args, &block) | |
if @str.respond_to?(name) | |
@str.send(name, *args, &block) | |
else | |
super | |
end | |
end | |
end | |
a = A.new | |
a.gsub(/ is /) do |m| | |
puts "last_match='#{Regexp.last_match}' m='#{m}'" | |
' is not ' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment