tags:

views:

113

answers:

1

I'm using modules as namespaces in ruby. How would I go about autoloading...something like autoload :"App::ModuleA", 'app/module_a that doesn't throw a "must be constant name" error?

+2  A: 

You need to pass a symbol to autoload (probably a typo in your question), and call it on the parent of the constant, like:

App.autoload :ModuleA, "app/module_a"
Marc-André Lafortune
I understand that. But I don't want to initialize on calling any Constant ModuleA, I want to call it when someone says `include App::ModuleA`
aharon
Indeed, which is why you want to call `App.autoload`, not just `autoload`. Try it out, it'll work as you want.
Marc-André Lafortune
aaaah... i see. thanks so much :)
aharon