where requested_controller_class is the name of an existing (controller)
class.
Is the above code the best of way of invoking respond_to? on the class
in question, or is there some better way to get the actual class object
based solely on it’s name?
Is the above code the best of way of invoking respond_to? on the class
in question, or is there some better way to get the actual class
object
based solely on it’s name?
Thanks,
Wes
Since you are in a Rails app the better way of doing that would be
like this:
There are a couple of solutions given. Assuming your class name is in
the variable named ‘quiz’ this (from James II) does it:
quiz.split(“::”).inject(Object) { |par, const| par.const_get(const) }
where requested_controller_class is the name of an existing (controller)
class.
Is the above code the best of way of invoking respond_to? on the class
in question, or is there some better way to get the actual class object
based solely on it’s name?