From: Jules Jacobs Date: 2006-03-11T19:38:32+09:00 Subject: Re: named method arguments with defaults Language support for named arguments will be in Ruby 2.0 (hopefully :P) On Saturday, March 11, 2006, at 6:48 PM, wrote: > >Jules Jacobs wrote: >> You can use merge: >> >> def a_method(*options) >> options = {:size => 45, :length => 12}.merge(options) >> >> # do stuff >> end >> >> a_method(:size => 44) >> >> *should* work. >> > >This works when I remove the asterisk from the (*options). >Makes sense, I guess, since when I call: > >a_method(:size => 21, :weight => 22) > >With the asterisk specified, the arguments are folded into an array, >and merge can't take an array as an argument when called on a Hash. >Without the asterisk, Ruby's "special features" takes the arguments I >passed to a_method as a Hash, since nothing came after the last x => y >assignment, and then merge works. > >Did I decipher this correctly ? > >In any case, your proposal (without the asterisk) works nicely. In the >1st edition of "Programming Ruby" the authors noted that by Ruby 1.8, >named arguments will be built into the language. I assume this hasn't >happened yet ? > >Thanks >Eli > > Jules -- Posted with http://DevLists.com. Sign up and save your time!