From: Brian Candler Date: 2010-09-23T17:17:49+09:00 Subject: Re: Unexpected behaviour of defined? under 1.8.x Rick Denatale wrote: >> I would expect defined? line to raise an RuntimeError,... > > Why? > > defined? is there to check WITHOUT raising an runtime error I think the point is the autoload stuff. If you have autoload set up for A::B, and you are checking "defined? A::B::C", then of course A::B has to be autoloaded before you check A::B::C. But when an exception is raised in the source file which is being autoloaded, it just finishes at that point silently, so you end up with half a file loaded. Here is another example: ---- a.rb ---- module A autoload :B, "b.rb" end p defined?(A::B::C) # nil p defined?(A::B::C) # "constant" ---- b.rb ---- module A class B puts "Starting" C = 123 raise "Oops" puts "Never get here" end end -- Posted via http://www.ruby-forum.com/.