From: Josh Cheek Date: 2010-12-04T08:08:14+09:00 Subject: Re: cast object to object --0016363101bb0d74820496898048 Content-Type: text/plain; charset=ISO-8859-1 On Fri, Dec 3, 2010 at 11:01 AM, Rick DeNatale wrote: > On Fri, Dec 3, 2010 at 11:35 AM, Robert Klemme > wrote: > > > >> name_of_my_class.to_class # Create a class out of the user input > > > > That sounds more like it. > > > > David, you could do > > > > class_name = ... # fetch the name from somewhere > > dave = Object.const_get(class_name).new > > Or for a more robust solution which can also handle strings like > "Module::Class" have a look at the String#constantize method from > activesupport (part of Rails) > > Here is a link https://github.com/rails/rails/blob/master/activesupport/lib/active_support/inflector/methods.rb#L89-128 If you wish to use it, you can copy it and any other methods it depends on, or you can use the gem itself: require 'active_support' "FireWatir::Link".constantize # => FireWatir::Link --0016363101bb0d74820496898048--