instance method attribute_names

Ruby on Rails 8.1.2

Since v7.1.6

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

Signature

attribute_names()

Returns an array of attribute names as strings.

class Person
  include ActiveModel::Attributes

  attribute :name, :string
  attribute :age, :integer
end

person = Person.new
person.attribute_names # => ["name", "age"]
Source
# File activemodel/lib/active_model/attributes.rb, line 146
    def attribute_names
      @attributes.keys
    end

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

Defined in ActiveModel::Attributes

Type at least 2 characters to search.

↑↓ navigate · open · esc close