From: Xavier Noria Date: 2007-06-23T05:53:58+09:00 Subject: Re: eval going boom On Jun 22, 2007, at 10:30 PM, Giles Bowkett wrote: >> > CHALLENGE: rewrite the above code to not use eval at all. For that >> > matter, don't even use #send. >> >> original_obj.attributes.each{|attr, value| >> new_obj.update_attribute(attr.to_sym, value)} > > prettier: > > original_obj.attributes.each do |attr, value| > new_obj.update_attribute(attr.to_sym, value) > end You don't even need #to_sym :-). Note that rewrite has the side- effect of actually saving those attributes of new_object in the database, whereas the original assignments didn't. Perhaps that's OK though. -- fxn