The title is a bit confusing, so let me explain.
I have 3 Model classes called Table1, Table2, and Table3. All three tables have the "total" column.
This is what I want to be able to do:
index = either 0, 1, or 2 tableNames = ["Table1", "Table2", "Table3"] tableNames[index].total
^ Obviously I can't do that because tableNames[index] returns a string, not a reference to the actual class itself.
This is what I'm currently doing:
index = either 0, 1, or 2 if index == 0 then Table1.total elsif index == 1 then Table2.total elsif index == 2 then Table3.total end
I guess what I want to do is a bit analogous to the "send" method in ruby, where you can use variables as method names.
Is there a way to do this, or do I have to do the if elsif check? This makes the code longer and clunkier and I'm wondering if there's a better way. Thanks!