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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:50:32+00:00 2026-05-10T22:50:32+00:00

Background: I have a module which declares a number of instance methods module UsefulThings

  • 0

Background:

I have a module which declares a number of instance methods

module UsefulThings   def get_file; ...   def delete_file; ...    def format_text(x); ... end 

And I want to call some of these methods from within a class. How you normally do this in ruby is like this:

class UsefulWorker   include UsefulThings    def do_work     format_text('abc')     ...   end end 

Problem

include UsefulThings brings in all of the methods from UsefulThings. In this case I only want format_text and explicitly do not want get_file and delete_file.

I can see several possible solutions to this:

  1. Somehow invoke the method directly on the module without including it anywhere
    • I don’t know how/if this can be done. (Hence this question)
  2. Somehow include Usefulthings and only bring in some of it’s methods
    • I also don’t know how/if this can be done
  3. Create a proxy class, include UsefulThings in that, then delegate format_text to that proxy instance
    • This would work, but anonymous proxy classes are a hack. Yuck.
  4. Split up the module into 2 or more smaller modules
    • This would also work, and is probably the best solution I can think of, but I’d prefer to avoid it as I’d end up with a proliferation of dozens and dozens of modules – managing this would be burdensome

Why are there lots of unrelated functions in a single module? It’s ApplicationHelper from a rails app, which our team has de-facto decided on as the dumping ground for anything not specific enough to belong anywhere else. Mostly standalone utility methods that get used everywhere. I could break it up into seperate helpers, but there’d be 30 of them, all with 1 method each… this seems unproductive

  • 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. 2026-05-10T22:50:32+00:00Added an answer on May 10, 2026 at 10:50 pm

    If a method on a module is turned into a module function you can simply call it off of Mods as if it had been declared as

    module Mods   def self.foo      puts 'Mods.foo(self)'   end end 

    The module_function approach below will avoid breaking any classes which include all of Mods.

    module Mods   def foo     puts 'Mods.foo'   end end  class Includer   include Mods end  Includer.new.foo  Mods.module_eval do   module_function(:foo)   public :foo end  Includer.new.foo # this would break without public :foo above  class Thing   def bar     Mods.foo   end end  Thing.new.bar   

    However, I’m curious why a set of unrelated functions are all contained within the same module in the first place?

    Edited to show that includes still work if public :foo is called after module_function :foo

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

Sidebar

Ask A Question

Stats

  • Questions 182k
  • Answers 182k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The %d format is a signed integer (decimal). Integers are… May 12, 2026 at 4:21 pm
  • Editorial Team
    Editorial Team added an answer You can use a User-defined function or a view instead… May 12, 2026 at 4:21 pm
  • Editorial Team
    Editorial Team added an answer I don't understand why these objects need to be created… May 12, 2026 at 4:21 pm

Related Questions

Background I am developing a highly modular application in pure Action Script 3 (we
I have a module Routines.pm: package Routines; use strict; use Exporter; sub load_shortest_path_matrices {
We have a staged environment with 1 CMS and 3 Slave servers I want
First things first, I am a Python beginner, with a typical C++/Java background for

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.