0

In lines like:

require "./hello.rb"

What does the single period do? I know that using 2 periods is going back a directory from current location.

Also, is there a difference in the following:

require_relative "../file.rb"

require "../file.rb"

philip yoo
  • 2,462
  • 5
  • 22
  • 37

1 Answers1

2

In Unixy systems, the dot refers to the current working directory. The two dots in your second and third examples, refer to the parent of your working directory.

As for require_relavive vs require see this question: What is the difference between require_relative and require in Ruby?

Short answer: If your ruby script lives in /scripts/bin/, and you run it from /home/work :

  • require "./file.rb" pulls in /home/work/file.rb
  • require_relative "./file.rb" pulls in /scripts/bin/file.rb
Community
  • 1
  • 1
Dmitri
  • 2,658
  • 2
  • 25
  • 41