philip yoo
philip yoo

Reputation: 2522

What does the single period in `require "./file_name.rb"` do?

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"

Upvotes: 0

Views: 85

Answers (1)

Dmitri
Dmitri

Reputation: 2748

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

Upvotes: 2

Related Questions