From: Lars Christensen Date: 2009-06-11T00:03:43+09:00 Subject: Match data variables I understand that $~ and its friends ($&, $1, ...) are method local, but: Can a custom method mimic the behaviour of String#match, String#=~ etc and set the match data for the caller? def expect(pattern) gets =~ pattern or fail end expect /(\d+)/ p $1 #=> nil p $~ #=> nil :-( I would like $~ to contain the match data here.