1 2 |
|
Given a module Foo
, how do you define a nested module Bar
?
1 2 3 4 |
|
There’s a number of ways. First, most obvious one is to eval a string.
1 2 3 4 5 6 7 8 9 10 11 |
|
While this certainly works and gets job done, it has some flaws. First, it’s a string, so some editors and IDEs will get confused and lose coloring/completion. Second, there’s no validation on module name. In best case, you’ll get compiler error. In worst case, you’ll get hard to track bugs.
1 2 3 4 5 6 7 |
|
This one is better. You clearly state that you’re going to set a constant, and module name is pretty restricted.
Are there other ways to do this?