From: Marc-antoine Kruzik Date: 2009-09-06T03:06:30+09:00 Subject: Re: something.new( :attribute => value) thing Tim Hunter wrote: > When the trailing method arguments are key => value pairs, Ruby collects > them into a hash and passes the hash as the last argument to the method. > Frequently the keys are symbols such as :opts or :x. The keys don't have > to be symbols, though. > > See http://www.softiesonrails.com/2007/8/27/ruby-101-hashes-are-cool I know the hashes, but I didn't know what was the best way to use arguments this way (my first post). Nice link. > 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 : a = A.new("hello", "world", :x => 10, :y => 20, :z => "red") a = A.new("hello", "world", :z => "red", :y => 20, :x => 10) a = A.new("hello", "world", :z => "red") a = A.new("hello", "world", :x => 10) Thank you very much, 7stud. -- Posted via http://www.ruby-forum.com/.