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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:50:46+00:00 2026-05-24T01:50:46+00:00

I have a class called Story that is associated with a class called User

  • 0

I have a class called Story that is associated with a class called User.
I also have a class called Parser that extends Story with parsing abilities (such as finding the nouns, for example).

class User < ActiveRecord::Base
    has_many :stories
end

class Story < ActiveRecord::Base
    belongs_to :user
    attr_accessible :title, :content
end

class Parser < Story
    def find_nouns
        self.content.do_something
    end
end

Say I want to create a new story for the first user in my database. Normally, I would simply do that using

User.first.stories.new(:title => 'Foo', :content => 'Bar')

How would I achieve that and still associate the record with the first story elegantly?

Something along these line:

User.first.stories.new(:title => 'Foo', :content => 'Bar').find_nouns

The problem is, the base class doesn’t have access to the find_nouns method — it belongs to StoryParser.

  • 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-24T01:50:47+00:00Added an answer on May 24, 2026 at 1:50 am

    Your Parser class looks like it should be a module mixed into either the Story class or instances, because it’s one aspect of a story.

    http://en.wikipedia.org/wiki/Aspect-oriented_programming

    Here’s the module:

    module Parser
      def find_nouns
        ...
      end
    end
    

    Mix it into the class with include:

    class Story
      include Parser
    end
    

    Or mix it into instances of Story:

    @user.stories.first.extend(Parser).find_nouns
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class called UserContext that tracks the activities of a given user
Let's say I have a class called Store that has many Employees. My RESTful
I have a class called DatabaseHelper that wraps a DbConnection. What's the proper way
I have a class called User with static function loginRequired(), which returns false if
I have a whole bunch of divs that have a class called ofint .
I have a little class called Stuff that I want to store things in.
I have a class called Device that accepts two policies as far as I
The story goes like this: I have an abstract class called Algorithms and a
Back story: I have a class that handles a database query. The problem is
The goal is to have a singleton data controller class called FetchData.h/.m that pulls

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.