0

I am ruby beginner. Two file is here first file attached to second file by using require. But first file does not load.

first.rb

puts "First File"

second.rb

require 'first'
puts "Second File"

I am getting error:-

/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- first.rb (LoadError)
from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from second.rb:2:in `<main>'

Please tell us. How to solve this problem.

1
  • This should work. Look that the files are in same directory and look that you don't have typos in your file names. Commented Feb 27, 2017 at 5:27

1 Answer 1

2

require_relative "image_utils"

Based on your Ruby version, using require assumes that image_utils.rb is in the $LOAD_PATH (this requires additional setup) as Ruby 1.9 has removed the current directory from the load path. Use require_relative instead.

Ruby will first try to resolve the file by its absolute path. Then, if it isn't found then it will check on the $LOAD_PATH as mentioned above, if not then it will throw a LoadError

http://ruby-doc.org/core-2.0.0/Kernel.html#method-i-require

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.