I'm trying to practice using the autoload function in a Ruby module. I have two modules A and B. I want to load module B in A's namespace but I'm getting an uninitialized constant error. Both files are in the same folder. Here is my code:
a.rb
module A
end
A.autoload(:B, "./b.rb")
A::B.test #this line causes the error.
b.rb
module B
def self.test
puts "test called"
end
end
Error:
Traceback (most recent call last):
a.rb:7:in `<main>': uninitialized constant A::B (NameError)
Did you mean? A::B
B