Need help to make the require-relative path expression

Hi,

Suppose I do have FS as below :

foo (b.rb)
>--bar
     >--baz (a.rb)

Now in side the program a.rb I want to include the code b.rb. How to
write the `require-relative` expression?

Thanks

···

--
Posted via http://www.ruby-forum.com/.

require-relative '../../b'

or

require-relative '../../b.rb'

···

--
Posted via http://www.ruby-forum.com/.

Follow the code below :

__FILE__ # => "home/kirti/Ruby/test.rb"

p File.expand_path('./so.rb',__FILE__)
p File.expand_path('../so.rb',__FILE__)
p File.expand_path('~/so.rb',__FILE__)

output

"/home/kirti/Ruby/test.rb/so.rb"
"/home/kirti/Ruby/so.rb"
"/home/kirti/so.rb"

My understanding :

(a) "/home/kirti/Ruby/test.rb/so.rb"

File.expand_path('./so.rb',__FILE__) produces something like
home/kirti/Ruby/test.rb/./so.rb. Now as `.` means current directory,so
the above code produced.

(b) "/home/kirti/Ruby/so.rb"

File.expand_path('../so.rb',__FILE__) produces something like
home/kirti/Ruby/test.rb/../so.rb. Now as `..` means go to parent
directory,so the above code produced,by dropping `test.rb`.

(c) "/home/kirti/so.rb"

File.expand_path('~/so.rb',__FILE__) produces something like
home/kirti/Ruby/test.rb/~/so.rb. Now as `~` means go to home
directory,so the above code produced,by adding the so.rb after home
directory.

Is my understanding of rules applied to 3 different cases are correct?
If not please correct me..

···

--
Posted via http://www.ruby-forum.com/.

David Unric wrote in post #1123566:

require-relative '../../b'

or

require-relative '../../b.rb'

Thanks for the reply.

What is the difference between `require-relative './b.rb' and
`require-relative '../../b.rb'` ?

···

--
Posted via http://www.ruby-forum.com/\.