Skip to content

Instantly share code, notes, and snippets.

View mansakondo's full-sized avatar

Mansa Keïta mansakondo

View GitHub Profile
@mansakondo
mansakondo / load_path.unshift File.expand_path(path, __FILE__).md
Last active July 24, 2019 15:47
load_path.unshift File.expand_path(path, __FILE__)

$:.unshift File.expand_path(path, __FILE__)

I saw this line of code somewhere and i felt kind of confuse about it and intimidate. That's why, i'll try to explain what i've found so far (if there is any errors, feel free to point them out).

What is this $: ?

This alien thing $: is a shortcut referencing the $LOAD_PATH. What is the $LOAD_PATH ? The $LOAD_PATH is a global variable as you can tell from $ at the beginning. A global variable is a variable which is accessible from everywhere in a given context. For example take a look at the function below :