From: Robert Klemme Date: 2005-04-18T16:39:37+09:00 Subject: Re: self "Trans" schrieb im Newsbeitrag news:1113782539.239967.177710@z14g2000cwz.googlegroups.com... > > Robert Klemme wrote: > > Btw, I would find something like this useful in the std lib: > > > > class Class > > def properties(*h) > > h = h[0] if h.size == 1 > > initial = {} > > > > h.each do |name, val| > > attr_accessor name > > initial[name]=val unless val.nil? > > end > > > > unless initial.empty? > > alias :new_plain :new > > class< > define_method(:new) do |*a| > > obj = allocate > > initial.each {|name, val| obj.send("#{name}=".to_sym, val)} > > obj.instance_eval { initialize(*a) } > > obj > > end > > end > > end > > > > h > > end > > end > > Ubfortunately, I think it is a bit dangerous to mess with #new like > this as a standard practice. Yet I do not see any other way to set the > instance vars. Agree or no? Yes - for current versions. But with wrappers (or hooks) this will be easier in 2.0 I guess. Kind regards robert