If you enter script/console into a Rails project and enter $: you will get an array containing all the directories needed to load Ruby. The conclusion from this little exercise is that $: is an array. Thus, you can perform functions on it, for example, add other directories using the unshift method or the << operator. As you implied in your statement, $: and $LOAD_PATH are the same.
The disadvantage of this is the quick and dirty way, as you mentioned, this: if you already have a directory in your download path, it will be repeated.
Example:
I have a plugin that I created called by todo. My directory is structured like this:
/ --- vendor
|
| --- / plugins
|
| --- / todo
|
| --- / lib
|
| --- / app
|
| --- / models
| --- / controllers
|
| --- / rails
|
| --- init.rb
In the init.rb file, I entered the following code:
#
Notice how I tell the code block to perform actions within the block in the row models, “controllers” and “models”, where I repeat the “models”. (FYI, %w{ ... } is another way to tell Ruby to contain an array of strings). When I run script/console , I type the following:
>> puts $:
And I type this in such a way that reading the contents in a line is easier. The output I get is:
...
...
./Users/Me/mySites/myRailsApp/vendor/plugins/todo/lib/app/models
./Users/Me/mySites/myRailsApp/vendor/plugins/todo/lib/app/controllers
./Users/Me/mySites/myRailsApp/vendor/plugins/todo/lib/app/models
As you can see, although this is a simple example that I could create using a project that I am currently working on, if you are not careful, a quick and dirty way will lead to repeated paths. A longer path will check for duplicate paths and ensure that they do not occur.
If you are an experienced Rails programmer, you probably have a very good idea of what you are doing, and you probably will not make the mistake of repeating paths. If you are a beginner, I would go with a longer path until you understand what you are doing.