From: "ara.t.howard" Date: 2007-11-22T09:20:43+09:00 Subject: Re: Dynamically call classes On Nov 21, 2007, at 4:02 PM, jacob.dunphy@gmail.com wrote: > And with this, you can do the var = Kernel.const_get("ClassName") and > you have a reference to that class for the scope of your operation. imho const_get is just to fragile for most uses, i prefer something like this: cfp:~ > cat a.rb class Class def self.for string value = Thread.new do $SAFE = 4 eval string.to_s, TOPLEVEL_BINDING.dup end.value raise ArgumentError unless value.is_a? Class value end end p Class.for('File::Stat') p Class.for('Foo::Bar') cfp:~ > ruby a.rb File::Stat a.rb:6:in `eval': (eval):1: uninitialized constant Foo (NameError) from a.rb:4:in `value' from a.rb:4:in `for' from a.rb:14 a @ http://codeforpeople.com/ -- we can deny everything, except that we have the possibility of being better. simply reflect on that. h.h. the 14th dalai lama