-1

How can I navigate back one or multiple directories in Ruby?

For example:

users/luigi/test/folder/file.rb

If I'm in the folder directory and want my file.rb script to load a file from within the test directory, how can I do that?

Something like:

require /../required_file.rb

Luigi
  • 5,233
  • 14
  • 46
  • 106

2 Answers2

3

You can use require_relative

require_relative "../test/file.rb"
Community
  • 1
  • 1
Dan Grahn
  • 8,638
  • 3
  • 36
  • 71
0
require_relative "../requred_file.rb"
toro2k
  • 18,715
  • 7
  • 60
  • 69
Donovan
  • 15,789
  • 4
  • 21
  • 34