Zhao_Yi
(Zhao Yi)
1
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.
···
--
Posted via http://www.ruby-forum.com/.
Maybe you meant to prefix the first line in base_cls.rb with "require"?
Stefan
···
2009/1/30 Zhao Yi <youhaodeyi@gmail.com>:
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?
Zhao_Yi
(Zhao Yi)
3
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.
···
--
Posted via http://www.ruby-forum.com/\.