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
thumb rules when you use require, always use path in require statement [mostly when you use windows platform]
if you use
loadyou need to placefilename.rbbut 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
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@jdoe is suggest
require_relativethat’s good approachbut I am getting below error