Create a gist now

Instantly share code, notes, and snippets.

@tai2 /a.rb
Created Jul 17, 2016

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