uninitialized constant error

Z

Zhao Yi

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.
 
S

Stefan Lang

2009/1/30 Zhao Yi said:
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?

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

Stefan
 
Z

Zhao Yi

Stefan said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,128
Latest member
ElwoodPhil
Top