ruby - Uninitialized constant (Name Error) creating object -
i trying instantiate new object calling class keep getting error , don't know why. still new ruby might missing here. getting error:
testa.rb:3 in `initialize': uninitialized constant testa::testb (nameerror) testa.rb:7:in `new' testa.rb:7:in `<main>'
here code: ** these 2 classes in separate files **
class testa def initialize @test = testb.new end end test = testa.new class testb def test_method print "hello" end end
you have require file test_b class definition. if name test_b.rb
looks like:
require_relative "test_b" class testa def initialize @test = testb.new end end test = testa.new
Comments
Post a Comment