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

  • Home
  • SEARCH
  • 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 6002047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:55:18+00:00 2026-05-23T00:55:18+00:00

Hey everyone! I am having trouble with understanding modules — I have two files,

  • 0

Hey everyone! I am having trouble with understanding modules — I have two files, one named “modfile.rb” with the module, and one named “main.rb” that runs the code:

# modfile.rb  
module Module1
  def method1
    puts "SUCCESS!"
  end
end

# main.rb  
require 'modfile'
Module1.method1

Unfortunately, instead of SUCCESS! appearing on my screen, I get this:

<internal:lib/rubygems/custom_require>:29:in 'require': no such file to load -- modfile (LoadError)
  from <internal:lib/rubygems/custom_require>:29:in 'require'
  from main.rb:1:in '<main>'

I think (though I may be wrong) that Ruby is looking to the lib/…. file inside the Ruby directory on my computer, while modfile.rb is saved in the same directory as main.rb. How do I fix this problem (other than by moving the module’s file?)

PS. one guide suggested I add the line “require ‘rubygems'” but I already did and got the same error.

  • 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-23T00:55:19+00:00Added an answer on May 23, 2026 at 12:55 am

    If modfile.rb and main.rb are in the same directory, make sure that you aare calling main.rb from the directory it’s in, ie:

    ruby main.rb
    

    As I believe that is the directory that the Ruby interpreter will be looking in for any require files.

    Edit: as @the-tin-man points out, the behaviour has changed for Ruby 1.9.

    To be completely on the safe side, you can do:

    require File.join(File.dirname(__FILE__), "modfile")
    

    One other thing:

    def method1
    

    … should be:

    def self.method1
    

    … since you are calling the method as a class level method.

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

Sidebar

Related Questions

Hey everyone, i am having trouble finding a memory leak. all off my retain
Hey everyone, I am having a little trouble debugging my code. Please look below:
Hey everyone, I've been having some trouble in C, i'm using a variety of
Hey everyone, I'm having trouble configuring my remote debugging set up. I've been searching
Hey everyone. I'm having a bit of trouble running a query / php combination
Hey everyone. I am having some issues on my end and hopefully it's just
Hey everyone, I am having a problem with a website I'm trying to build;
Hey everyone, I'm working on a hex dump utility made in Java. I'm having
Hey everyone, running into a bit of an issue, I have created all my
Hey everyone... I'm not too familiar with PHP... but I have PHP code that

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.