From: Eero Saynatkari Date: 2006-09-02T08:30:20+09:00 Subject: Re: How can I do this without eval... James Mccarthy wrote: > def load_default_attributes(model_name, options = {}) > fixture = options[:fixture] || :default > attributes = temp_attributes = model = {} > instance_eval <<-FIN > temp_attributes = #{model_name.to_s.pluralize}("#{fixture}") send model_name.to_s.pluralize, fixture > model = #{model_name.to_s.capitalize} self.class.const_get model_name.to_s.capitalize > FIN > . > . > . > end > > I know there must be a neater way to get hold of a class (or in this > case a Rails model) and with the temp_attributes to get hold of a > fixture, can anybody shed some metaprogramming light? The above should work in principle; however, take a look at ri Object#send and Module#const_get in case you run into any problems. (Disclaimer: respondent is not proficient with Rails.) > Thanks. -- Posted via http://www.ruby-forum.com/.