Forum: Ruby uninitialized constant error

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.
7fbd0e99b27064b14793f028022974e5?d=identicon&s=25 Zhao Yi (youhaodeyi)
on 2009-01-30 13:21
I have three ruby classes, see below:

1. base_cls.rb

File.dirname(__FILE__)+'/cls_factory'
class BaseCls

  def self.say
    ClsFactory.say
  end
end
BaseCls.say

2. sub_cls.rb

require File.dirname(__FILE__)+'/base_cls'

class SubCls  < BaseCls
end

3. cls_factory.rb

require File.dirname(__FILE__)+'/sub_cls'

class ClsFactory
  def self.get_cls
    SubCls.new
  end
end

When I run base_cls.rb, I got this error:

base_cls.rb:5:in `say': uninitialized constant BaseCls::ClsFactory
(NameError)

I don't understand why this error happens? Can anyone help me on this?

thanks.
40613e55d7082e5f08429dfb50d0680e?d=identicon&s=25 Stefan Lang (Guest)
on 2009-01-30 19:26
(Received via mailing list)
2009/1/30 Zhao Yi <youhaodeyi@gmail.com>:
> end
>
> base_cls.rb:5:in `say': uninitialized constant BaseCls::ClsFactory
> (NameError)
>
> I don't understand why this error happens? Can anyone help me on this?

Maybe you meant to prefix the first line in base_cls.rb with "require"?

Stefan
7fbd0e99b27064b14793f028022974e5?d=identicon&s=25 Zhao Yi (youhaodeyi)
on 2009-01-31 03:00
Stefan Lang wrote:
> Maybe you meant to prefix the first line in base_cls.rb with "require"?
>
> Stefan

Oh, sorry, I forgot to type the 'require'. But the problem is still
there.
This topic is locked and can not be replied to.