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 7815115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:24:49+00:00 2026-06-02T05:24:49+00:00

Apologies in advance – I’m very much a learner, and writing projects as a

  • 0

Apologies in advance – I’m very much a learner, and writing projects as a means to learn. In this one, I’m trying to extend ActiveRecord so that I can do the following…

In my model definition, call …

attr_special :field, :field

Then, elsewhere, be able to access this list through something like

Model.special_attributes

Probably something really obvious. I’m fine extending ActiveRecord, but I’m not even sure what I’m searching for for guidance beyond this (constructor?)…

  • 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-06-02T05:24:52+00:00Added an answer on June 2, 2026 at 5:24 am

    You can define something like the code below to create custom DSL in your models:

    module SpecialAttributes
      module ClassMethods
        def attr_special(*attrs)
          class_attribute :special_attributes
          self.special_attributes = attrs
        end
    
        def special_attributes
          self.special_attributes
        end
      end
    
      module InstanceMethods
        # some code here
      end
    
      def self.included(base)
        base.extend ClassMethods
        base.send :include, InstanceMethods
      end
    
    end
    
    class ActiveRecord::Base
      include SpecialAttributes
    end
    

    I reopen ActiveRecord::Base class instead of use inheritance because it’s more common in Ruby that inheritance.

    I like to use submodules called ClassMethods and InstanceMethods in my module and use self.included method to add them in the base class. So you can use ‘include MyModule’ without have to know if you add instance or class methods.

    I hope I can help you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Apologies in advance if this is a silly question, am very much a beginner.
This is a very wide-ranging/vague question, but here goes. Apologies in advance. The app
This may be a very simplistic question, so apologies in advance, but I am
Apologies in advance if this becomes a very long question... Background Info I have
I'm not so savvy with MYSQL, so my apologies in advance is this is
This may be a bit of an abstract question, so apologies in advance. I
This, I'm sure is a pretty basic question about JavaScript, so apologies in advance.
First, a thank you in advance. Second, this is my first post so apologies
Apologies in advance but I have never seen this error before and don't know
This could potentially be a dumb question so apologies in advance if it 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.