Parameter list too long in initialize method I have an initialize method for a class that looks like this:

def initialize(
  site:,
  name:,
  date_online: '-',
  date_offline: '-',
  date_modified: '-',
  date_tagged: '-',
  tags: []
)
  @site          = site
  @name          = name
  @date_online   = date_online
  @date_offline  = date_offline
  @date_modified = date_modified
  @date_tagged   = date_tagged
  @tags          = tags
end


However, RuboCop is telling me that I should:



Metrics/ParameterLists: Avoid parameter lists longer than 5 parameters. [7/5]


So, what is the best way to rectify this? It's an initializer, so all those parameters are necessary. Is the desired solution to use a hash?



def initialize(args)
  @site          = args[:site]
  @name          = args[:name]
  @date_online   = args[:date_online]   || '-'
  @date_offline  = args[:date_offline]  || '-'
  @date_modified = args[:date_modified] || '-'
  @date_tagged   = args[:date_tagged]   || '-'
  @tags          = args[:tags]          || []
end


Then how should I manually handle the fact that site and name are required? I could add some code after the assignments that will throw an error if the required fields aren't present:

raise ArgumentError unless @site &amp;&amp; @name


That makes sense to me. But I assume the makers of RuboCop know what they're talking about, which leads me to suspect that there's a standard for this sort of thing.
An in-between solution for you might be:

def initialize(site:, name:, **options)
  @site          = site
  @name          = name
  @date_online   = options[:date_online]   || '-'
  @date_offline  = options[:date_offline]  || '-'
  @date_modified = options[:date_modified] || '-'
  @date_tagged   = options[:date_tagged]   || '-'
  @tags          = options[:tags]          || []
end


You would probably want to raise an error if an unexpected key was passed in as part of options.