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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:16:22+00:00 2026-05-28T13:16:22+00:00

I’m designing/building a system of classes that all derive from a single base class.

  • 0

I’m designing/building a system of classes that all derive from a single base class.

The goal is to have easy-to-use inherited macro methods that look something like this:

class Something < A::Base
  full_name 'Something that goes bump in the night.'
end

Any code should be able to ask the class for this information (or, likely, normalized/derived infomation) later on via class-level accessor method(s).

puts Something.full_name
  # => "Some kind of calculated value that may or may not go bump in the night."

 

Given that A::Base includes/extends/somehow-otherwise-mixes-in both a module with the macro method that works something like this:

module MacroMethods
  private
  def full_name(full_name)
    # non-trivial, one-time-only set-up code exists here in actual usage
  end
end

and a module with the class-level accessor method that works something like this:

module AccessorMethods
  public
  def full_name
    # a non-trivial, runtime-calculated value is returned here in actual usage
  end
end

no matter how I mix them in, I’m continually running into naming conflicts (i.e. ‘wrong number of arguments (1 for 0) (ArgumentError)’) between the two.

Note: full_name is the simplest example of what is needed; other, more-complex macros/accessors ensure the non-flexible constraints of macro methods needing to be declared inside the class and needing to be set once-and-only-once.


My question is two-fold:

  1. Is there a way to make this all work inside of the A::Base class?
  2. Is this the right way to do this in Ruby? Is there a better way go about it, achieving the same result?

Options that have been considered:

  • Calling either the macro or accessor method(s) something else.
    (e.g. in Something class: set_up_full_name 'Something that …')
    Downside is that the naming is confusing and unconventional.

  • Making the accessor method(s) instance-level instead of class-level.
    (e.g. puts a_something.full_name')
    Downside is that the traits set up by the macros are inherent to the class, not to each instance (in some cases, only a reference to the class may be available, not an instance).

  • Creating a single method that handles both macro and accessor functionality.
    (e.g. in A::Base class: def self.full_name(*args) …)
    Downside is that the macro methods can no longer be private and the RDoc looks like sh*t.

  • Using abstact/virtual-ish methods instead.
    (e.g. in Something class: def self.full_name; 'Something that …'; end)
    Downside is that this is more code in sub-classes and is more of a Objective-C (or C++, or Java, …) thing than a good Ruby paradigm.

  • 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-28T13:16:23+00:00Added an answer on May 28, 2026 at 1:16 pm

    Slipp, I read your question carefully. There is no way you can have 2 different methods called full_name defined on the same object at the same time. BUT, you could do something like this:

    module MacroMethods
      private
      def full_name(full_name)
        # non-trivial, one-time-only set-up code exists here in actual usage
        # this method can only be called once in the definition of any given class,
        #   because after the first call, it will be redefined!
        extend AccessorMethods
      end
    end
    
    module AccessorMethods
      public
      def full_name
        # a non-trivial, runtime-calculated value is returned here in actual usage
      end
    end
    
    class Base
      extend MacroMethods
    end
    
    class Something < Base
      full_name 'after this call, I will get a new full_name method!'
    end
    
    class SomethingElse < Base
      full_name 'so will I!'
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a bunch of posts stored in text files formatted in yaml/textile (from
I am doing a simple coin flipping experiment for class that involves flipping a
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.