From: Chris Shea Date: 2007-02-23T06:40:10+09:00 Subject: Re: Best way to get a class object from its name? On Feb 22, 2:21 pm, Wes Gamble wrote: > All, > > In my Rails app., I'm doing something like this: > > eval("#{requested_controller_class}.respond_to?('session_data_not_needed_by?')") > > 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? > > Thanks, > Wes > > -- > Posted viahttp://www.ruby-forum.com/. Getting class objects was one of the problems in Ruby Quiz #113. See: http://www.ruby-forum.com/topic/97203 or http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/90223b4082d864fa/ 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) }