class method self.new

Ruby on Rails 8.1.2

Since v7.0.10

Available in: v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

self.new(attributes = {})

Initializes a new model with the given params.

class Person
  include ActiveModel::API
  attr_accessor :name, :age
end

person = Person.new(name: 'bob', age: '18')
person.name # => "bob"
person.age  # => "18"

Parameters

attributes opt = {}
Source
# File activemodel/lib/active_model/api.rb, line 80
    def initialize(attributes = {})
      assign_attributes(attributes) if attributes

      super()
    end

Defined in activemodel/lib/active_model/api.rb line 80 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveModel::API

Type at least 2 characters to search.

↑↓ navigate · open · esc close