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

The Archive Base Latest Questions

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

I have a more conceptual question in Rails… or Ruby for that matter: Is

  • 0

I have a more conceptual question in Rails… or Ruby for that matter:

Is it best to call a require right before the method that needs it, group my requires at the beginning of the class or somewhere in an initializer when Rails boots?

Does it matter from a performance point of view? From a readability point of view? Does it make a difference if I’m using Rails 3?

Thanks!

  • 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-16T11:22:08+00:00Added an answer on May 16, 2026 at 11:22 am

    If you’re concerned about performance then you should require things in the context of where they are needed so that if that portion of your code is not exercised, the library is not loaded. Any subsequent calls to require have no effect as that file has already been loaded. This ends up looking like something along the lines of:

    if (user.using_openid?)
      require 'openid'
    
      # ... Do OpenID stuff
    end
    

    While this is more efficient in terms of resources, it can make it very difficult to determine the dependencies of your application. Declaring these up-front makes it clear to other people maintaining the software. Keep in mind that “other people” always includes your future self when you’ve forgotten about some details of your application.

    You’re technically allowed to require anything at any time, late or early, but declaring your requirements up front is better from a design perspective. If you find that there is an element that is used only intermittently and takes an unusual amount of time or memory to load, then you should probably document that up front in your requirements file. For example:

    require 'library1'
    require 'library2'
    require 'library3'
    require 'library4'
    require 'library5'
    
    # Other libraries loaded as required:
    #  * slowimagelibrary
    #  * slowencryptionlibrary
    #  * openid
    

    Arguably this is less of an issue with bundler because you can have your gems declared up front more formally and the actual require call can come later.

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

Sidebar

Related Questions

this is more a conceptual question. Consider you have a php framework that runs
More of a design/conceptual question. At work the decision was made to have our
This is more of a conceptual question than anything. I have a base class
I have an interesting situation here this time. This more of a conceptual question,
This is more of a conceptual integrity question for something that's been bothering me.
I have more of a conceptual question. Assume one program running two threads. Both
I have a number of classes that are all related conceptually, but some more-so
I have more than one Event Listener that calls a specific function, and I
i have more viewcontroller that start from rootviewcontroller. So for example i start with
This is a conceptual question involving Hadoop/HDFS. Lets say you have a file containing

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.