I have a 2 scripts:
test1.rb
require 'test2.rb'
puts "hello"
test2.rb
puts "test"
I’m running this by executing ruby test2.rb test1.rb.
But only test is printed out and not hello.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
You only need to run
ruby test1.rband therequirestatement should pull in test2.rb for you – you don’t need to put it on the command line as well. (That will try and run test2.rb, passing the string ‘test1.rb’ as an argument, which is not what you want here)Edit: the
requirestatement does not look in the current directory by default when trying to find ‘test2.rb’. You can explicitly specify it by changing it to:require File.dirname(__FILE__) + '/test2.rb'