From: Brian Adkins Date: 2007-10-14T05:15:04+09:00 Subject: Re: Generation of initialize On Oct 13, 4:01 pm, Erik Veenstra wrote: > It can be as simple as this. > > gegroet, > Erik V. -http://www.erikveen.dds.nl/ > > ---------------------------------------------------------------- > > class Class > def generate_initialize(*vars) > define_method(:initialize) do |*args| > vars.zip(args) do |var, arg| > instance_variable_set("@#{var}", arg) > end > end > end > end > > class Foo > generate_initialize :a, :b, :c > end > > p Foo.new(1, 2, 3) Might as well define the attrs while you're at it so you can get the data out :)