From: ts Date: 2001-11-01T03:13:18+09:00 Subject: [ruby-talk:24003] Re: RCR: Fun with attribute shortcuts solves RCR #3 and more >>>>> "K" == Kevin Smith writes: K> --- Dan Schmidt wrote: >> Gunnar Andersson writes: >> >> | # file: AttrInitializer >> | class Module >> | def attr_initializer(*attrs) >> | alist = plist = "" >> | attrs.each do |v| >> | alist += "@#{v}," # >> @var1,@var2,@var3, >> ... >> | plist += "#{v}," # >> var1,var2,var3, ... >> | end >> | alist.chop!; plist.chop! # Remove last comma >> | class_eval "def initialize(#{plist}); #{alist} = >> #{plist}; end" >> | end >> | end >> >> Perhaps the generated initialize method could also check >> for the presence of a initialize_more (or a better name, >> hopefully) method and call it if it exists. K> I was thinking that it would be nice if you could pass in a K> block. The last thing attr_initializer would do before K> returning would be to yield. Well, the problem that I see with this that is not really equivalent with attr_accessor, attr_writer, ... * You can have only one attr_initializer unlike attr_accessor * attr_accessor is, at least for me, an optimization. attr_initializer is nor a macro nor an optimization * attr_initializer call class_eval this mean that it exist the possibilty that it can't work with $SAFE Guy Decoux