How do you infer all attributes, including attr_accessor attributes?

Let's say I have a custom class with column names and email:

Class User < ActiveRecord::Base
  attr_accessor :gender
end

user = User.new(:gender => 'male', :name => 'joe', :email => 'user@example.com')

If I need attributes that I can usually execute user.attributes, or user.inspect, or user.to_yaml. However, this does not give gender. Is there any way I can easily output everything?

+3
source share
1 answer

I do not believe that what you are trying to do is easy to do.

See this question:

How to iterate ActiveRecord attributes, including attr_accessor methods

+1
source

All Articles