I'm trying to avoid ever adding a redundant path to ruby's LOAD_PATH
. It's not a remarkably complicated task, I'm just wondering if there is a cleaner method then what I've come up with.
This is my current solution as it stands now:
def add_loadpath(new_path)
included = $LOAD_PATH.inject(false) do |acc,path|
acc || new_path == File.expand_path(path)
end
$LOAD_PATH.unshift new_path unless included
end
Then instead of doing the usual $LOAD_PATH.unshift SOME_PATH
you'd call
add_loadpath SOME_PATH
This is to avoid problems when the load path includes two paths that point to the same folder but are not the same string. For example foo/../bar
and bar