Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly does $:.unshift(File.expand_path("../../lib", __FILE__)) do?

There are a lot of threads on here about this already I know but none of the titles have this worded exactly like I did. I hope that we can clear this up a bit.

$:.unshift(File.expand_path("../../lib", __FILE__)) 

You see something like this in a lot of Ruby code. Opinions vary whether this is proper or not.

Can we get a little explaination for each of its parts? There realy is a lot going on here. I only understand some of it.

like image 206
Douglas G. Allen Avatar asked Sep 07 '13 18:09

Douglas G. Allen


1 Answers

$: holds Load path for scripts and binary modules by load or require. . And Array#unshift will prepend the new path to $:. File#expand_path Converts a pathname to an absolute pathname. __FILE__ is already answered here What does __FILE__ mean in Ruby?.

like image 173
Arup Rakshit Avatar answered Sep 30 '22 18:09

Arup Rakshit