Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6116107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:10:06+00:00 2026-05-23T15:10:06+00:00

Beginning with Rails 3.1, class_inheritable_accessor produces deprecation warnings, telling me to use class_attribute instead.

  • 0

Beginning with Rails 3.1, class_inheritable_accessor produces deprecation warnings, telling me to use class_attribute instead. But class_attribute behaves differently in an important way which I will demonstrate.

A typical use of class_inheritable_attribute would be a presenter class, like so:

module Presenter
  class Base
    class_inheritable_accessor :presented
    self.presented = {}

    def self.presents(*types)
      types_and_classes = types.extract_options!
      types.each {|t| types_and_classes[t] = t.to_s.tableize.classify.constantize }
      attr_accessor *types_and_classes.keys
      types_and_classes.keys.each do |t|
        presented[t] = types_and_classes[t]
      end
    end
  end
end

class PresenterTest < Presenter::Base
  presents :user, :person
end

Presenter::Base.presented => {}
PresenterTest.presented => {:user => User, :person => Person}

But using class_attribute, subclasses will pollute their parents:

Presenter::Base => {:user => User, :person => Person}

Which is not desired behavior at all. Is there another type of accessor that behaves the correct way, or do I need to switch to another pattern altogether? How should I replicate the same behavior without class_inheritable_accessor?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:10:07+00:00Added an answer on May 23, 2026 at 3:10 pm

    class_attribute won’t pollute its parent if it’s used as intended. Make sure you’re not changing the mutable items in-place.

    types_and_classes.keys.each do |t|
      self.presented = presented.merge({t => types_and_classes[t]})
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is probably really simple, but I'm still sorta beginning rails and can't seem
I am beginning to use Backbone and am trying to transition my Rails backend's
So I am beginning to work with Rails and I get some of the
Since the beginning I always hat this one problem with rails, short urls without
Since beginning to use VB.NET some years ago I have become slowly familiar with
I'm beginning to work on mailing-list software we use internally (EDIT: though we send
I am beginning to work on my first OpenGL iPhone app, but I've hit
This bug may be lurking since the beginning of ruby-mode , but I noticed
I'm trying to figure the best way to query a date range from rails...I
I'm beginning to learn Ruby on Rails, and looking at other peoples code. Is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.