class method
self.new
Ruby on Rails 5.1.7
Since v4.0.13 Last seen in v6.1.7.10Signature
self.new(attributes = {})
Initializes a new model with the given params.
class Person
include ActiveModel::Model
attr_accessor :name, :age
end
person = Person.new(name: 'bob', age: '18')
person.name # => "bob"
person.age # => "18"
Parameters
-
attributesopt = {}
Source
# File activemodel/lib/active_model/model.rb, line 78
def initialize(attributes = {})
assign_attributes(attributes) if attributes
super()
end
Defined in activemodel/lib/active_model/model.rb line 78
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveModel::Model