From: Ralph Shnelvar Date: 2012-02-21T15:31:53+09:00 Subject: Re: Metaprograming question about initialize Bartosz, Monday, February 20, 2012, 10:19:41 AM, you wrote: BD> 2012/2/20 Ralph Shnelvar : >> >> What I want to do is not change the interface but the implementation. That is, I want to get a list of the names of the arguments by introspection. BD> It is much simpler and IMO makes much more sense not to figure out BD> variable names while already having variables, but to figure out their BD> contents while having names. Like this: BD> class Class BD> def attr_accessor_init *meths BD> attr_accessor *meths BD> define_method :initialize do |*args| BD> meths.each_with_index do |m, i| BD> self.send :"#{m}=", args[i] BD> end BD> end BD> end BD> end irb(main):013:0>> class A irb(main):014:1>> attr_accessor_init :a, :b, :c irb(main):015:1>> end irb(main):029:0>> A.new 4, 6, 8 =>> # BD> (This is, essentially, what Struct class does.) BD> -- Matma Rex This is an elegant solution. Not quite what I wanted .... but I learned a lot from it. Thank you.