From: Brian Candler Date: 2011-07-22T21:20:43+09:00 Subject: Re: create object by reflection 7stud -- wrote in post #1012360: > Brian Candler wrote in post #1012354: >> >> Or if you want to call 'build' with a variable number of args: >> >> def build(instance,clazz,*args) >> @instances[instance] = Object.const_get(clazz).new(*args) >> end >> > > `initialize': wrong number of arguments (3 for 2) (ArgumentError) > > `initialize': wrong number of arguments (1 for 2) (ArgumentError) Show your exact code. I would guess that you are passing an array of 3 elements for args, when your class's initialize method takes only two. Here's how it works: >> class Foo >> def initialize(a,b) >> @a, @b = a, b >> end >> end => nil >> args = ["foo", "bar"] => ["foo", "bar"] >> Foo.new(*args) => # -- Posted via http://www.ruby-forum.com/.