From: Robert Klemme Date: 2012-12-17T00:31:13+09:00 Subject: Re: by value - by reference, circular reference On Sun, Dec 16, 2012 at 3:22 AM, tamouse mailing lists wrote: > if you object to long parameter lists, consider passing a hash. > This may still have a lot of code on the calling side, but it > is at least rather more understandable vs. just passing > in values. > > a = A.new({ > :option1 => 'Something', > :option2 => 'or' > :option3 => 'other' > }) Curly brackets are superfluous here. And you can use the new Syntax in 1.9: a = A.new( option1: 'Something', option2: 'or', option3: 'other' ) > then the method definition is > > def initialize(options = {}) > > # ... code > > end > > This form is used all over the place, all the time. I don't like that too much because what seems to be a good idea in the beginning can come back later to haunt you. Stuffing everything in a Hash just to avoid longer parameter lists is worthless without documenting which keys the class expects. But if you write the documentation you can as well also use proper arguments. This is really only a good solution if a lot of arguments are optional. If not, I'd prefer a proper argument list because the caller must provide them anyway. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/