Forum: Ruby why is not work ?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Chung C. (Guest)
on 2007-07-19 19:13
Hi all,

   module A
   end
   A.autoload(:B, "b")
   A::B.doit            # autoloads "b"

result :
  uninitialized constant A::B (NameError)
Todd B. (Guest)
on 2007-07-19 19:30
(Received via mailing list)
On 7/19/07, Chung C. <removed_email_address@domain.invalid> wrote:
> Hi all,
>
>    module A
>    end
>    A.autoload(:B, "b")
>    A::B.doit            # autoloads "b"
>
> result :
>   uninitialized constant A::B (NameError)

Do you have a file named "b"?
Chung C. (Guest)
on 2007-07-20 04:36
Todd B. wrote:
> On 7/19/07, Chung C. <removed_email_address@domain.invalid> wrote:
>> Hi all,
>>
>>    module A
>>    end
>>    A.autoload(:B, "b")
>>    A::B.doit            # autoloads "b"
>>
>> result :
>>   uninitialized constant A::B (NameError)
>
> Do you have a file named "b"?

Hi,

Yes, I have.

A.autoload?(:B)    # "b"
Chung C. (Guest)
on 2007-07-20 05:12
Chung C. wrote:
> Todd B. wrote:
>> On 7/19/07, Chung C. <removed_email_address@domain.invalid> wrote:
>>> Hi all,
>>>
>>>    module A
>>>    end
>>>    A.autoload(:B, "b")
>>>    A::B.doit            # autoloads "b"
>>>
>>> result :
>>>   uninitialized constant A::B (NameError)
>>
>> Do you have a file named "b"?
>
> Hi,
>
> Yes, I have.
>
> A.autoload?(:B)    # "b"

irb(main):001:0> module A
irb(main):002:1> end
=> nil
irb(main):003:0> A.autoload(:B,"b")
=> nil
irb(main):004:0> A.autoload?(:B)
=> "b"
irb(main):005:0> A::B.hello
NameError: uninitialized constant A::B
        from (irb):5
irb(main):006:0> require "b"
=> false
irb(main):007:0> B.hello
"hello"
=> nil
Nobuyoshi N. (Guest)
on 2007-07-20 07:32
(Received via mailing list)
Hi,

At Fri, 20 Jul 2007 10:12:47 +0900,
Chung C. wrote in [ruby-talk:260876]:
> irb(main):006:0> require "b"
> => false
> irb(main):007:0> B.hello
> "hello"
> => nil

Seems b.rb defines ::B but doesn't A::B.
This topic is locked and can not be replied to.