From: Chris Carter Date: 2007-03-27T06:50:25+09:00 Subject: Re: Some inflection (?) questions On 3/26/07, Joshua Muheim wrote: > Hi all > > I have the following code snipped: > > @country = Country.new > > Instead of hardcoding @country and Country I'd like to use the contents > of two strings: > > instance_var_name = 'country' > class_name = 'Country' > > How can this be achieved? > > Thanks a lot for help and yes, I'm working on my Ruby skills but I'm not > quite there yet. ;-) > > Josh > > -- > Posted via http://www.ruby-forum.com/. > > you can use the instance_variable_set and const_get methods. exempli gratia: def set_country(ivar_name,klass) self.instance_var_set('@'+ivar_name, Object.const_get(klass).new) end -- Chris Carter concentrationstudios.com brynmawrcs.com