From: Gavin Sinclair Date: 2004-11-29T18:32:10+09:00 Subject: Re: Seeking advice on some method names On Monday, November 29, 2004, 3:53:43 PM, David wrote: >> > I'm not sure what either of these adds to const_get -- or, to put it >> > another way, why there should be a special method to do (essentially) >> > a const_get only for strings that represent class names. >> >> Well, IIRC, const_get doesn't work with symbols that contain "::". In >> other words, const_get( "Test::Unit" ) would fail--you'd have to do >> const_get("Test").const_get("Unit"), which becomes cumbersome. I can >> think of several instances in my Net::SSH and Net::SFTP stuff alone >> where a standard #get_class method would have been useful (though far >> from necessary). > Oh right, I forgot about that. There are some "deep" const_get > implementations floating around... along the lines of: > def deep_const_get(str) > str.split('::').inject(Object) {|a,b| a.const_get(b) } > end > which might help. That's precisely how it's implemented in extensions. BTW it's now Class.by_name. Class.by_name("::Test::Unit") -> Test::Unit Gavin