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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:36:15+00:00 2026-05-29T10:36:15+00:00

I have a category class that I want to Use that acts on a

  • 0

I have a category class that I want to “Use” that acts on a third-party service class. The service class has a bunch of xxxRequest and xxxResponse classes plus additional child classes for data for each xxx call.

I want to automatically apply categories to each of the additional classes at the same time as the service category is applied, with the same scope.

I could list all the category classes in the use block but there are a lot and I don’t want to expose that detail. The base classes are out of my control so I can’t use @category/@mixin.

Currently I have a static initialise method in my service category that does a series of mixin calls (as well as adding the odd extra constructor). This works ok but doesn’t provide the scoping I want.

Is there an easier way that I have missed?

  • 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-29T10:36:15+00:00Added an answer on May 29, 2026 at 10:36 am

    I’m not sure I understand what you are trying to do. If you are trying to use many categories at once in the same block of code but you don’t want to list all those categories each time you want to use them (please correct me if that is not what you meant), you can put that long use inside a method that takes a block of code (a Closure) as a parameter and then use that method instead of the long use. Something like:

    @Category(String)
    class ShoutCategory {
        def shout() {
            this.toUpperCase() + '!'
        }
    }
    
    @Category(Integer)
    class ToEnglishCategory {
        def toEnglish() {
            // Only works for integers in 0..5 for now...
            ['zero', 'one', 'two', 'three', 'four', 'five'][this]
        }
    }
    
    def useAwesomeExtensions(Closure cl) {
        use (ShoutCategory, ToEnglishCategory) {
            cl()
        }
    }
    
    useAwesomeExtensions {
        // Here we can do all sorts of magic things.
        println 3.toEnglish().shout() // Outputs "THREE!"
    }
    
    // "hello".shout() -> Would throw a MissingMethodException here
    

    In this silly example, the String and Integer classes would be the classes that you want to augment but you don’t have access to, and the useAwesomeExtensions acts like a big category that includes a bunch of other categories. Hope that helps 🙂

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

Sidebar

Related Questions

I have several subclasses of UIViewController that I want to use a single category
i have two models: class Category has many :jobs end class Job belongs_to :category
I have category model that has a tree structure. In my database I have
Just want to check: If you have a class that uses a method added
I have a big class. To sum up, it has only one method that
I have a class from an external library that I want to extend with
I have an Item entity that has a ManyToOne relationship to a Category entity.
If I have the following class defined, class Category { /** * * @var
I have three models: class Address < ActiveRecord::Base has_many :jobs end class Category <
I have 2 clases: public class products { public string category; public string name;

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.