This code will print "#<RuntimeError: bork>" in JRuby 1.7.x as well as all MRI versions I tested, but "nil" in JRuby 9.0.0.0:
begin
begin
raise 'bork'
rescue TypeError
end
ensure
p $!
end
Removing the inner begin … rescue makes it print "#<RuntimeError: bork>" again. It looks like rescue clears $!. The error matched by the inner rescue doesn't matter, and catching the error and re-raising it also leaves $! unset.