class Company include ActiveModel::Validations include ActiveModel::Conversion extend ActiveModel::Naming attr_accessor :cnpj, :name validates :cnpj, :cnpj => true def initialize(attributes = {}) attributes.each do |key, value| instance_variable_set("@#{key}", value) end end end