load-path

Adding a directory to $LOAD_PATH (Ruby)

笑着哭i 提交于 2019-11-26 21:19:37
I have seen two commonly used techniques for adding the directory of the file currently being executed to the $LOAD_PATH (or $:). I see the advantages of doing this in case you're not working with a gem. One seems more verbose than the other, obviously, but is there a reason to go with one over the other? The first, verbose method (could be overkill): $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__))) unless $LOAD_PATH.include?(File.expand_path(File.dirname(__FILE__))) and the more straightforward, quick-and-dirty: $:.unshift File.dirname(__FILE__) Any reason to go with one over the

Adding a directory to $LOAD_PATH (Ruby)

懵懂的女人 提交于 2019-11-26 06:57:11
问题 I have seen two commonly used techniques for adding the directory of the file currently being executed to the $LOAD_PATH (or $:). I see the advantages of doing this in case you\'re not working with a gem. One seems more verbose than the other, obviously, but is there a reason to go with one over the other? The first, verbose method (could be overkill): $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__))) unless $LOAD_PATH.include?(File.expand_path(File.dirname(__FILE__))) and the more