Reputation: 1728
Most answers I've seen on adding a directory to the load path in Ruby has been around using unshift
, for eg:
$:.unshift File.dirname(__FILE__)
Can't you use push
instead? Is it deliberate that most examples are using unshift
vs. push
when adding a directory to the load path?
Upvotes: 0
Views: 39
Reputation: 211740
You can use either, but they're checked in order. unshift
puts it in at the highest precedence, push
as the lowest.
Normally this doesn't matter, you typically don't have duplicate module names, however if you want to override something you'll need to have your path earlier than the others. This makes unshift
more desirable.
One thing to note is it's usually better to use $LOAD_PATH
instead of $:
so what you're doing is made more clear. Unless you're a Perl veteran you might not know off the top what $:
is, and even then there's a bunch of those variables that are very similar.
Upvotes: 1