What is the best practice in Ruby regarding creating methods? Is it to
create a named set of parameters to pass (specific method signature) OR
should I be passing a hash which may be more readable/future proof? For
example:
Option 2 seems to be more readable and flexible from what I can see. Is
this the recommended Ruby best practice for implementing Ruby methods
that
have more than a couple of parameters which have to be passed?
Don’t forget option 3: a few required positional parameters followed
by a hash of optional parameters. This is an approach used by Rails,
and it’s a nice compromise for methods with a lot of parameters.
I prefer this approach to use hash params (named hashed params). It’s
easier to know the method’s parameters, you don’t need read the method
body, to knows the parameters names
It’s easier to implement tests (TDD), you don’t have N possibilities to
the parameteres, because you have default values