From: Joel VanderWerf Date: 2003-11-29T13:16:46+09:00 Subject: Re: How to access Bar in Foo when Foo::Bar exists? Wejn wrote: > Hi, > I can't figure out how to: > > class Foo > class Bar << RuntimeError; end > > def something > begin > # ... > rescue Bar # i want Bar, not Foo::Bar > raise Bar # i want Foo::Bar, correct. > end > end > end > > Does anyone have idea how to do that? > (IIRC, In c++ this is done via "::" operator) (trying to avoid puns about raising the bar...) Ruby also has a :: operator: begin class Bar < SyntaxError; end class Foo class Bar < RuntimeError; end def something begin yield rescue ::Bar # i want Bar, not Foo::Bar raise Bar # i want Foo::Bar, correct. end end end Foo.new.something do raise Bar; end rescue Exception => e p e.class # => Foo::Bar end