From: "B. K. Oxley (binkley)" Date: 2005-03-30T05:03:48+09:00 Subject: Re: attr :? Florian Gross wrote: > Glenn Smith wrote: >> class Meta >> def self.has_many( sym ) >> attr_tmp = "def #{sym.to_s} \n" >> attr_tmp << " @#{sym.to_s} = [] unless @#{sym.to_s}\n" >> attr_tmp << " @#{sym.to_s}; end" >> eval ( attr_tmp ) >> end >> end > > class Meta > def self.has_many(sym) > ivar = :"@#{sym}" > define_method(sym.to_sym) do > new_value = instance_variable_get(ivar) || [] > instance_variable_set(ivar, new_value) > new_value > end > end > end What is the difference between these two approaches? * Is one more 'culturally correct'? * Does one perform better? * Is one more future-proof? Thanks, --binkley