我需要在特殊情況下捕獲NameError。但我不想捕獲NameError的所有子類。有沒有辦法做到這一點?Rescue NameError但不是NoMethodError
begin
# your code goes here
rescue NameError => exception
# note that `exception.kind_of?` will not work as expected here
raise unless exception.class.eql?(NameError)
# handle `NameError` exception here
end
此解決方案符合我的需求。 – PascalTurbo