If you need just a way to call a method if a variable has method name string, then, refer to @sawa's answer. If, for some specific reason, you need to invoke a module method using []
syntax, then, read on.
If you say method is part of module, then, it must be its singleton method as shown below, only then, you can invoke it using DailyQueries.new_teachers
syntax
module DailyQueries
def self.new_teachers
["A", "B"]
end
end
You cannot invoke module methods using []
syntax - hence, you may have to add a method to module that does this for you.
module DailyQueries
def self.[] name, *params
method(name)[*params]
end
#... other methods definitions
end
Now, you can do this:
DailyQueries[queries[0]]
If the method had any parameters, you can pass arguments as:
DailyQueries[queries[0], "param1", "param2", :another_param]