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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:20:54+00:00 2026-06-05T10:20:54+00:00

I have two Ruby scripts, and I am calling those files and I am

  • 0

I have two Ruby scripts, and I am calling those files and I am getting an error.

I have r1.rb and r2.rb. When I call r1.rb and r2.rb from r3.rb I get this error:

C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- r1 (LoadError)
        from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from r3.rb:1:in `<main>'

r1.rb is:

def random
    rand(1000000)
end

r2.rb is:

def random
    (rand(26) + 65).chr
end

r3.rb is:

require 'r1'
require 'r2'

puts random
  • 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-06-05T10:20:56+00:00Added an answer on June 5, 2026 at 10:20 am

    thumb rules when you use require, always use path in require statement [mostly when you use windows platform]

    if you use load you need to place filename.rb but no need to pass file path. [First Check the requirement and use load because it is load every time in memory when call]

    here I am modifying your code

    require 'C:/PLACE YOUR FILE PATH HERE/r1'
    require 'C:/PLACE YOUR FILE PATH HERE/r2'
    
    puts random
    

    Please let me know if this works for you

    let me add one more things

    Same way when you use irb, you have to do same way

    >irb
    irb(main):001:0> require 'c:/rubycode/test.rb'
    => true
    

    @jdoe is suggest require_relative that’s good approach

    but I am getting below error

    irb(main):001:0> require_relative 'test'
    LoadError: cannot infer basepath
            from (irb):1:in `require_relative'
            from (irb):1
            from C:/Ruby193/bin/irb:12:in `<main>'
    
    irb(main):002:0> require_relative 'rubycode/test'
    LoadError: cannot infer basepath
            from (irb):2:in `require_relative'
            from (irb):2
            from C:/Ruby193/bin/irb:12:in `<main>'
    
    irb(main):003:0> require_relative 'c:/rubycode/test'
    LoadError: cannot infer basepath
            from (irb):3:in `require_relative'
            from (irb):3
            from C:/Ruby193/bin/irb:12:in `<main>'
    
    irb(main):004:0> require 'c:/rubycode/test'
    => true
    irb(main):005:0>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two ruby files. The first is require 'www/poster' poster = Poster.new() The
Possible Duplicate: Why do this Ruby object have two to_s and inspect methods that
I have two Ruby arrays, and I need to see if they have any
In Ruby, I want to have two threads running at the same time, and
can you have a ruby for loop that has two indexes? ie: for i,j
I have once again fleshed out Ruby, after two years of not touching it,
Have two folders with approx. 150 java property files. In a shell script, how
I have two tables users and work_orders. Now I need to get work_orders results
I have two XML files. The first XML has a bunch of nodes that
I have two scripts which use Mechanize to fetch a Google index page. I

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.