From: "David A. Black" Date: 2007-08-21T10:41:32+09:00 Subject: Re: get a class from its name Hi -- On Tue, 21 Aug 2007, Rolando Abarca wrote: > This is how i'm currently getting a class object from a name: > > cname = "A::B::C::D" > klass = cname.split("::").inject(Kernel) {|a,b| a.const_get(b)} > > I think it's pretty elegant, but I'm always happy to hear other ways to do it > ;-) > Anyone does this in some other way? (I don't want to eval code...) I think it's usually done the way you've got it there. It's one of those things that people write over and over (like map_with_index and singleton_method), hopefully some day to enter the core as const_get_deep or something. David -- * Books: RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) RUBY FOR RAILS (http://www.manning.com/black) * Ruby/Rails training & consulting: Ruby Power and Light, LLC (http://www.rubypal.com)