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

1

8

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.

Pinpoint answered 7/9, 2013 at 18:38 Comment(0)
A
13

$: 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?.

Adapt answered 7/9, 2013 at 18:42 Comment(1)
Thanks for that explaination @Arup.Pinpoint

© 2022 - 2024 — McMap. All rights reserved.