'After upgrading to Ruby 3, unable to pass multiple arguments to my "initialize" method

I recently upgraded to Rails 6 with Ruby 3. I have this in a controller

my_object = MyObject.new(my_object_params, @header)

The object “initialize” method is defined like so

  def initialize(params, header)
    super(params)
    user&.header = header
  end

But now when attempting to initialize the object, I get the error

 ArgumentError:
   wrong number of arguments (given 2, expected 0..1)

What’s the proper way in Ruby 3 to pass multiple arguments to an object during initialization?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source