[#1094] Re: [ruby-cvs] ruby, ruby/lib: * eval.c (ev_const_defined, ev_const_get), variable.c — Dave Thomas <dave@...>

> * eval.c (rb_mod_autoload, rb_mod_autoload_p): new method;

12 messages 2003/05/29
[#1095] Re: [ruby-cvs] ruby, ruby/lib: * eval.c (ev_const_defined, ev_const_get), variable.c — nobu.nokada@... 2003/05/29

Hi,

Re: [ruby-cvs] ruby, ruby/lib: * eval.c (ev_const_defined, ev_const_get), variable.c

From: matz@... (Yukihiro Matsumoto)
Date: 2003-05-30 15:09:40 UTC
List: ruby-core #1105
In message "Re: [ruby-cvs] ruby, ruby/lib: * eval.c (ev_const_defined, ev_const_get), variable.c"
    on 03/05/30, nobu.nokada@softhome.net <nobu.nokada@softhome.net> writes:

|> I think autoload should require X::XXX to be defined, so that should
|> raise exception for this case, because X::XXX is referencing ::XXX
|> which can be seen via X.  The confusion was caused by X::XXX as ::XXX
|> if there's no X::XXX.  This has its own reason but still confusing.
|
|At first I thought so too.  But, in this case, refereced is
|X::XXX which is exactly autoloaded one but not ::XXX.

??

1  module X
2    autoload :XXX, "x.rb"
3  end
4  p X::XXX'


On line 2, autoload is declared, so that "x.rb" will be loaded when
X::XXX is referenced.  And I believe "x.rb" should define XXX under X,
not ::XXX.

On line 4, X::XXX is referenced, so that autoload is executed, "x.rb"
is loaded.  Then, in autoload process, it should check if X::XXX is
defined.  In this case, x.rb does not define XXX under X.  This means
autoload process should raise NameError.  Right?

							matz.

In This Thread