Skip to content

Commit 03121e6

Browse files
authored
activemodel: Remove ActiveModel::Attributes#initialize (#641)
Now `ActiveModel::Attributes#initialize` has been typed as `() -> untyped`. But it's incorrect. The original implementation takes positional arguments via varargs and passes it to other constructors using `super` method. So it does not care the number of arguments. refs: * https://github.com/rails/rails/blob/v6.1.7.8/activemodel/lib/active_model/attributes.rb#L75 * https://github.com/rails/rails/blob/v7.2.1/activemodel/lib/active_model/attributes.rb#L106 Usually, many models using ActiveModel::Model takes keyword arguments (ex. `Person.new(name: 'John')`. But, unfortunately, the current type of ActiveModel::Atributes conceals the type of constructors for them. This removes the definition of ActiveModel::Attributes#initialize not to conceal the type of constructor.
1 parent 3a67350 commit 03121e6

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

gems/activemodel/6.0/_test/test.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ class Person
99
def foo? = true
1010
end
1111

12-
Person.new.send(:valid?)
12+
person = Person.new(name: 'John Doe')
13+
person.valid?

gems/activemodel/6.0/_test/test.rbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
class Person
2+
include ActiveModel::Model
23
include ActiveModel::Validations
34
extend ActiveModel::Validations::ClassMethods
45

gems/activemodel/6.0/activemodel-generated.rbs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -852,8 +852,6 @@ module ActiveModel
852852
def define_default_attribute: (untyped name, untyped value, untyped `type`) -> untyped
853853
end
854854

855-
def initialize: () -> untyped
856-
857855
# Returns a hash of all the attributes with their names as keys and the values of the attributes as values.
858856
#
859857
# class Person

0 commit comments

Comments
 (0)