[#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: nobu.nokada@...
Date: 2003-05-30 13:24:12 UTC
List: ruby-core #1104
Hi,

At Fri, 30 May 2003 21:36:20 +0900,
Yukihiro Matsumoto wrote:
> |>    x.rb:
> |>       XXX = 1
> |> 
> |>    [~/tmp] ruby -ve 'module X; load "x.rb";end; p X::XXX'
> |>    ruby 1.8.0 (2003-05-29) [powerpc-darwin6.6]
> |>    1
> |> 
> |>    [~/tmp] ruby -ve 'module X; autoload :XXX, "x.rb";end; p X::XXX'
> |>     ruby 1.8.0 (2003-05-29) [powerpc-darwin6.6]
> |>    -e:1: uninitialized constant X::XXX (NameError)
> |
> |Thank you.  Fixed now.
> 
> 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.  You
might mean the case:

  autoload :XXX, "x.rb"; module X; p XXX; end

so I agree that this XXX should not be autoloaded ideally.  Or
a confused is me?

-- 
Nobu Nakada

In This Thread