im trying to figure out what exactly these methods are doing.
$:.unshift(File.join(APP_ROOT, 'lib'))
I know its for file paths but if this piece of code were to broken down into segments how would you describe each one?
So far I under stand the File.join part, which takes two arguments (the APP_ROOT variable, and the ‘lib’ directory.) It then unshifts something?
Thanks in advance.
$: is Ruby shorthand to the load path array, i.e. an array full of the paths that Ruby uses to look up external files when asked to require one (try running it in IRB).
In Ruby, .unshift is a method that takes the given path (in this case, whatever
File.join(APP_ROOT, 'lib')resolves to), and prepends it to the beginning of the load path array.This way Ruby will know to check the APP_ROOT/lib path the next time you do a
require 'myfile'line elsewhere in the app.