Problems/I want to achieve

I created a class called CalculateLocalPattern in Rails.
The following is the initialize method that is executed immediately after CalculateLocalPattern.new ().

# app/models/calcurate_local_pattern.rb
class CalcurateLocalPattern  Array, y_coo =>Array
        @x_coo = x_coo
        @y_coo = y_coo
        @coo = x_coo.zip (y_coo)
    attr_accessor: x_coo,: y_coo,: coo

I wanted to test with the Rails console and set the array to two arguments. Then

x = [1, 2]
y = [3, 4]
test = CalcurateLocalPattern.new (x, y)
Traceback (most recent call last):
        1: from (irb): 3
ArgumentError (wrong number of arguments (given 2, expected 0..1))
I was angry with


Also, if you try without any arguments,

test = CalcurateLocalPattern.new
Traceback (most recent call last):
        2: from (irb): 1
        1: from app/models/calcurate_local_pattern.rb: 3: in `initialize '
ArgumentError (wrong number of arguments (given 1, expected 2))

It will become. (There seems to be an error in initialize, so you should still need two arguments)

I think "wrong number of arguments" is an error that the number of arguments on the calling side is different from the number of arguments on the method side.
What causes the expected number of method-side arguments to change depending on the argument settings?

Tell someone.

Version information

Rails 5.2.3
Ruby 2.5.1

  • Answer # 1

    ApplicationRecord defines "initialize", so if you define it with its children, various things will happen.

    Did you make a child of ApplicationRecord, did you migrate and create a table in the DB?
    If so, please update with the corresponding parameters.