From: Dido Sevilla Date: 2005-05-27T15:10:49+09:00 Subject: Methods with lots of arguments Just went through a bit of refactoring on a bit of Ruby code that I've been writing, and have been following some of the guidelines here: http://rpa-base.rubyforge.org/wiki/wiki.cgi?GoodAPIDesign I've had a lot of methods in the old code that had lots and lots of arguments, and many of which had default values, and followed the suggestion on naming arguments by passing what is essentially a hash. The syntax for this looked a lot like the labeled arguments used in OCaml, and it seems like a good way of doing things. Now only if Ruby had actual support for this idiom. As it turns out, I wind up writing a lot of methods that look like this: def somemethod(args) requiredargs = [ :foo, :bar, :baz ] defaultargs = { :quux => nil, :blargle => nil } requiredargs.each { |arg| unless (args.has_key?(arg)) raise ArgumentError.new("missing required argument #{arg.to_s}") end } newargs = defaultargs.merge(args) ... end Is there at the very least some kind of library out there that can do all of this checking and merging automatically? If there is one, I think it should be mentioned in the RPA-base link. However, I think that this kind of idiom would be better as an official part of Ruby syntax.