foo.rb is a one-liner that puts __FILE__
irb -r ./foo.rb
gives me the absolute path to foo.rb. This is not the behavior if I run ruby foo.rb. Why is it happening in irb?
irb 0.9.6(09/06/30),
ruby 1.9.3p327
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.
The reason this happens in IRB is the same reason this would happen if you had written a program named
bar.rbwith the following contents.You will find that using IRB with the require as you do is no different than calling
bar.rbwhich has the require.From the documentation:
So this is including the path relative to the directory where the application was started up. Who knows where irb or bar are? When it is not clear, then the path is given as well.