5 Oct 04:27
[ruby-core:19127] Autoload and class definition
From: Tomas Matousek <Tomas.Matousek <at> microsoft.com>
Subject: [ruby-core:19127] Autoload and class definition
Newsgroups: gmane.comp.lang.ruby.core
Date: 2008-10-05 02:27:42 GMT
Subject: [ruby-core:19127] Autoload and class definition
Newsgroups: gmane.comp.lang.ruby.core
Date: 2008-10-05 02:27:42 GMT
I've found an interesting corner case of autoload behavior, which I think is wrong. Let's create a file load_c.rb with following 2 definitions: module M C = 1 end class F include M end --- Now this works: class F require 'load_c' class C # [1] end end It's because the class definition [1] of C doesn't look for constant C in included modules, only in the class F itself (if it did look in the included modules we would indeed get "C is not a class" TypeError). Now, let's do the same using constant auto-loading instead: class F autoload(:C, "load_c"); class C # => uninitialized constant F::C (NameError) end end It seems that autoload repeats the same constant resolution semantics that triggered it (otherwise C would be found in M and TypeError would be raised), yet it raises error if the constant is not found. This seems to be a bug. I would expect no exception. Tomas
RSS Feed