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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:44:56+00:00 2026-05-27T00:44:56+00:00

I am in a position at the moment where I have a plugins folder

  • 0

I am in a position at the moment where I have a plugins folder where there there could be 1 or 100 plugins to be loaded.

Now the problem is, each plugin requires an instance of a class defined within the startup ruby file.

A really simplified example would be:

#startup.rb

def load_plugins
    #... get each plugin file
    require each_plugin
end

class MuchUsedClass
    def do_something
        #...
    end
end

muchUsedInstance = MuchUsedClass.new
load_plugins

#some_plugin.rb

class SomePluginClass
    def initialize(muchUsedInstance)
        @muchUsedInstance = muchUsedInstance
    end

    def do_something_with_instance
        @muchUsedInstance.do_something
    end
end

somePluginInstance = SomePluginClass.new(muchUsedInstance)
somePluginInstance.do_something_with_instance

The main problem is that when you call require, it doesn’t have any clue about what has happened before it is being required. So I find it nasty making a global variable within the startup file just to satisfy all other required files, but it seems like one of the only ways to be able to pass some data down to an included file, I could also make a singleton class to expose some of this, but that also seems a bit nasty.

As I am still new to ruby and am still looking through the statically typed glasses, I will probably be missing a decent pattern to solve this, in C# I would opt for dependency injection and just hook everything up that way…

  • 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-27T00:44:57+00:00Added an answer on May 27, 2026 at 12:44 am

    Your example code does not have a global variable. Global variables have names that start with $. The code as you wrote it won’t work, because muchUsedInstance is just a local variable and will not be shared between different Ruby files.

    If you are not going to change the instance ever, you could easily store it as a constant:

    MuchUsedInstance = MuchUsedClass.new
    

    You could store it as a nested constant inside the class:

    MuchUsedClass::Instance = MuchUsedClass.new
    

    You could store it as an instance variable inside the class object, with a getter method that automatically creates it if it isn’t there already:

    def MuchUsedClass.instance
      @instance ||= MuchUsedClass.new
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I'm in quite some problem at the moment, I currently have a class
I have been using the jquery appear plugin for some time now, but it
at the moment i'm using this validation plugin: ( http://www.position-absolute.com/articles/jquery-form-validator-because-form-validation-is-a-mess/ ) but when it
I am in a position where I could become a team leader of a
i have a rather weird problem that should fix a bug in my current
at the moment i have this <div id=beau> <div> <input type=text id=lun name=lun size=24
Im working on some html stuff at the moment but have come across a
I have some services at the moment that return a dto with the following
I have this working ok(ish) in my game at the moment, but i'm not
I have this code: $('#label, #btlabel').live('hover',function(){ parent = $(this).parent().attr('id'); position = $(this).parent().position(); positionTop =

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.