class method self.new

Ruby on Rails 8.0.5.1

Since v7.0.10

Available in: v7.0.10 v7.1.6 v7.2.3.2 v8.0.5.1 v8.1.3.1 edge

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.

Use the arrow keys to navigate results, Enter to open one, Escape to close.

Keyboard shortcuts

/
Focus search
⌘K / Ctrl-K
Command palette
?
This help
Esc
Close