From: trans Date: 2009-10-03T04:20:24+09:00 Subject: Re: operating on a selection of objects On Oct 2, 10:54 am, James French wrote: > Hi, > > I want to be able to do operations to a selection of objects, something like this: > > class Config >   attr_accessor :name > end > > class ConfigSelection > >   def initialize(*configs) >     @configs = configs >   end > >   def name=(n) >     @configs.each{|c| c.name = n} >   end > > end > > a = Config.new > a.name = "a" > > b = Config.new > b.name = "b" > s = ConfigSelection.new(a, b) > s.name = "s" > > I was wondering if there might be a more elegant way of doing this, without having to explicitly duplicate all of Config's attributes in ConfigSelection? require 'facets/enumerable/every' s = [a,b] s.every.name = "s"