From: Tim Pease Date: 2007-08-21T11:43:45+09:00 Subject: Re: get a class from its name On 8/20/07, David A. Black wrote: > 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. > "A::B::C::D".to_class It could just be a wrapper for the core method rb_path2class -- which does the same thing in Ruby C API land. Blessings, TwP