From: Martin Boese Date: 2009-09-06T23:36:27+09:00 Subject: Re: something.new( :attribute => value) thing On Sun, 2009-09-06 at 03:06 +0900, Marc-antoine Kruzik wrote: > > A.send(:attr_accessor, key) > > send("#{key}=", val) > > This solution is what I was looking for. > With a bit of work, I will be able to write code like this : Hi Marc, I'd try to keep it simple: class A def initialize(param_a, param_b, options = {}) @x = options[:x] || 50 # defaults to 50 if not specified @y = options[:y] || 100 @z = options[:z] || 'red' puts "Initialized with #{@x}/#{@y}/#{@z}" end end a = A.new("hello", "world", :x => 10, :y => 20, :z => "red") Initialized with 10/20/red a = A.new("hello", "world", :z => "red", :y => 20, :x => 10) Initialized with 10/20/red a = A.new("hello", "world", :z => "red") Initialized with 50/100/red a = A.new("hello", "world", :x => 10) Initialized with 10/100/red - Martin