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

There are already many streams here, I know about this, but not one of the names formulated it in the same way as I did. Hope we reveal this a bit.

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

You see something similar in a lot of Ruby code. Opinions change whether it is right or wrong.

Can we get a little explanation for each of its parts? A lot is going on here. I understand only some of them.

+6
source share
1 answer

$: contains the download path for scripts and binary modules by loading or querying. And Array#unshift will add a new path to $: File#expand_path Converts a path to an absolute path. __FILE__ already answered here What does __FILE__ mean in Ruby? .

+11
source

Source: https://habr.com/ru/post/953395/