From: Anthony Eden Date: 2009-05-16T05:13:02+09:00 Subject: Re: obj.attr(qualifier) = value -- possible? On Fri, May 15, 2009 at 3:55 PM, Michael Schuerig wrote: > Joel VanderWerf wrote: > >> I'm pretty sure that's impossible -- there is no #() method, or #()=. >> But there is #[]=, and you can adapt your Proxy approach to use it: > > That's a good suggestion, but unfortunately, it doesn't fit in my case. > I'm trying to do this stuff in an extension module for a Rails has_many > :through association. It looks roughly like this > > class Role < ActiveRecord::Base >  validates_presence_of :type # actor, director, ... > end > > class Movie < ActiveRecord::Base >  has_many :roles >  has_many :participants, :through => :roles do >    def as(role) >      self.scoped(...) # joins and conditions omitted >    end >  end > end > > 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 -A -- GMU/IT d- s: a32 C++(++++)$ UL@ P--- L+(++) !E W+++$ !N o? K? w--- !O M++ V PS+ PE Y PGP t+ !5 X- R tv b++ DI+ D++ G- e++ h---- r+++ y++++** http://anthony.mp