From: Dan Schmidt Date: 2001-10-31T02:14:38+09:00 Subject: [ruby-talk:23857] Re: RCR: Fun with attribute shortcuts solves RCR #3 and more 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. That way you could set a bunch of member variables automatically, and then continue by doing other initialization such as setting other derived variables. -- http://www.dfan.org