B
Brian Schröder
I want to use methods in different modules depending on commandline switches. So I thought i'd use
module Module1
module SubModule1
def foo() end
end
module SubModule2
def foo() end
end
end
module Module2
module SubModule1
def foo() end
end
module SubModule2
def foo() end
end
end
m1 = Module1
m2 = SubModule1
m1::m2::foo()
to call the correct foo depending on m1 and m2.
This does not work, because when assigning SubModule1 to m2 it is not defined.
Logical conclusion, I want to name the module, not take the module when assigning the variable => I have to use a symbol. But then I do not want to call m2 on the Symbol :Module1, so somehow I have to go from symbol to module.
Is eval the only way to do this, or is there something more elegant?
Thanks,
Brian
module Module1
module SubModule1
def foo() end
end
module SubModule2
def foo() end
end
end
module Module2
module SubModule1
def foo() end
end
module SubModule2
def foo() end
end
end
m1 = Module1
m2 = SubModule1
m1::m2::foo()
to call the correct foo depending on m1 and m2.
This does not work, because when assigning SubModule1 to m2 it is not defined.
Logical conclusion, I want to name the module, not take the module when assigning the variable => I have to use a symbol. But then I do not want to call m2 on the Symbol :Module1, so somehow I have to go from symbol to module.
Is eval the only way to do this, or is there something more elegant?
Thanks,
Brian