Skip to content

Instantly share code, notes, and snippets.

@tai2
Created July 17, 2016 11:46
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 tai2/eaa11210a7c5e6d71196f099a936be80 to your computer and use it in GitHub Desktop.
Save tai2/eaa11210a7c5e6d71196f099a936be80 to your computer and use it in GitHub Desktop.
Regexp.last_match in the block of gsub should not be nil
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