From: Michael Schuerig Date: 2009-05-16T05:45:02+09:00 Subject: Re: obj.attr(qualifier) = value -- possible? Anthony Eden wrote: > On Fri, May 15, 2009 at 3:55 PM, Michael Schuerig > wrote: [...] >> This allows me to write code like >> >> movie.participants.as('actor') >> >> On top of that, I'd like to be able to write >> >> movie.participants.as('actor') = params[:movie][:actors] >> >> and that's where I'm stuck. > > If you're willing to use a block you could do > > movie.participants.as('actor') { params[:movie][:actors] } > > and then: > > def as(role, &block) > value = yield > end Another interesting suggestion. But I think I use def replace(role, value) ... end as there's a precedent in the Rails association methods for #replace and the generated #replace is not useful in this case anyway. Michael -- Michael Schuerig mailto:michael@schuerig.de http://www.schuerig.de/michael/