def create_many_arrays(*arraynames)
params = arraynames.join ','
arrays = ''
attrs = ''
arraynames.each do |name|
thename = name.to_s
arrays += "@#{thename} = []\n"
attrs += "attr_accessor :#{name}\n"
end
code = <<-END_OF_CODE
alias :__dion__initialize :initialize
#{attrs}
def initialize
__dion__initialize
#{arrays}
end
def initialize(*incoming)
__dion__initialize *incoming
#{arrays}
end
END_OF_CODE
class_eval code
end
class Foo
create_many_arrays :foo, :bar
end
f = Foo.new
f.foo
f.foo << 1
f.foo
class Bar
attr_accessor :a
def initialize(a)
@a = a
end
create_many_arrays :foo, :bar
end