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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T16:57:29+00:00 2026-05-14T16:57:29+00:00

I have a class (ActorClue) that has three attr_accessor defined within it. There are

  • 0

I have a class (ActorClue) that has three attr_accessor defined within it. There are a couple other common fields needed by other classes, so I put those common fields in a module (BaseClueProperties). I am including that module within my ActorClue class.

Here’s the code sampling :

module BaseClueProperties  
  attr_accessor :image_url
  attr_accessor :summary_text  
end

################
class BaseClue

  # http://stackoverflow.com/questions/2487333/fastest-one-liner-way-to-list-attr-accessors in-ruby    
  def self.attr_accessor(*vars)
    @attributes ||= []

    @attributes.concat vars

    super(*vars)
  end

  def self.attributes
    @attributes
  end

  def attributes
    self.class.attributes
  end

end

###############

class ActorClue < BaseClue

  attr_accessor :actor_name
  attr_accessor :movie_name
  attr_accessor :directed_by

  include BaseClueProperties

  .....
end

I instantiate the above with the following :

>> gg = ActorClue.new
=> #<ActorClue:0x23bf784>
>> gg.attributes
=> [:actor_name, :movie_name, :directed_by] 

Why is it only returning :actor_name, :movie_name, and :directed_by and not include :image_url and :summary_text?

I modified the BaseClueProperties to read the following :

module BaseClueProperties  
  BaseClue.attr_accessor :image_url
  BaseClue.attr_accessor :summary_text  
end

But still with the same result.

Any thoughts as to why my :image_url and :summary_text attributes aren’t getting added to my @attributes collection?

  • 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-14T16:57:30+00:00Added an answer on May 14, 2026 at 4:57 pm

    I can’t promise that my description of the reason is correct but the following code should fix the problem. I believe that your are adding attributes to the Module not to the class that it is included within. Anyhow replacing your module with the following should fix the problem.

    module BaseClueProperties
    
      def self.included(base)
        base.send :attr_accessor, :image_url
        base.send :attr_accessor, :summary_text
      end
    
    end 
    

    This should cause the including object to define attribute_accessors when it includes the module.

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

Sidebar

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.