-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,443
  • 15
  • 54
  • 108

2 Answers2

3

You can use require_relative

require_relative "../test/file.rb"
Community
  • 1
  • 1
Dan Grahn
  • 9,044
  • 4
  • 37
  • 74
0
require_relative "../requred_file.rb"
toro2k
  • 19,020
  • 7
  • 64
  • 71
Donovan
  • 15,917
  • 4
  • 22
  • 34