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?
views:
113answers:
1
+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
2010-06-02 18:53:42
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
2010-06-02 22:48:25
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
2010-06-02 23:05:53
aaaah... i see. thanks so much :)
aharon
2010-06-02 23:37:58