I'd say that if you are either:
- Having more than 6 method parameters
- Passing options that have some required, some optional and some with default values
You would most probably want to use a hash. It's much easier to see what the arguments mean without looking up in the documentation.
To those of you saying it's hard to figure what options a method takes, that just means that the code is poorly documented. With YARD, you can use the @option
tag to specify options:
##
# Create a box.
#
# @param [Hash] options The options hash.
# @option options [Numeric] :width The width of the box.
# @option options [Numeric] :height The height of the box.
# @option options [Boolean] :show_border (false) Whether to show a
# border or not.
def create_box(options={})
options[:show_border] ||= false
end
But in that specific example there's such few and simple parameters, so I think I'd go with this:
##
# Create a box.
#
# @param [Numeric] width The width of the box.
# @param [Numeric] height The height of the box.
# @param [Boolean] show_border Whether to show a border or not.
def create_box(width, height, show_border=false)
end