Method: ActiveRecord::AttributeMethods#attributes

Defined in:
lib/active_record/attribute_methods.rb

#attributesObject

Returns a hash of all the attributes with their names as keys and the values of the attributes as values.

class Person < ActiveRecord::Base
end

person = Person.create(name: 'Francesco', age: 22)
person.attributes
# => {"id"=>3, "created_at"=>Sun, 21 Oct 2012 04:53:04, "updated_at"=>Sun, 21 Oct 2012 04:53:04, "name"=>"Francesco", "age"=>22}


278
279
280
281
282
# File 'lib/active_record/attribute_methods.rb', line 278

def attributes
  attribute_names.each_with_object({}) { |name, attrs|
    attrs[name] = read_attribute(name)
  }
end