Need help to make the require-relative path expression


Suppose I do have FS as below :

foo (b.rb)
|–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?


require-relative ‘…/…/b’


require-relative ‘…/…/b.rb’

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)



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.

© “/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

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs