L
Lars Christensen
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.
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.