B
Brandon Lawler
Hi; I'm a comp sci undergrad, with decent (maybe 6 months off and on)
Ruby/Rails experience. I'm competent with the syntax and have written a
number of Ruby scripts for various things.
Requiring local files always drove me nuts, due to the need to
explicitly declare the directory in the require statement with require
File.dirname(__FILE__) + '\somefile.rb', which was rather bulky and
inelegant.
I stumbled onto a solution while reading about the array $:. I've hunted
for a solution like this many times, but never found it on Google
anywhere. The solution is this line, affixed to the top of the main
script file:
$: << File.dirname(__FILE__) unless $:.include? File.dirname(__FILE__)
With this, a "require 'somefile.rb'" statement for local files will work
for ANY file linked through all the scripts in the application. My
question is this: why do I not find this method used anywhere? Is there
some staggering disadvantage to doing this that did not occur to me?
Thanks,
Grays
Ruby/Rails experience. I'm competent with the syntax and have written a
number of Ruby scripts for various things.
Requiring local files always drove me nuts, due to the need to
explicitly declare the directory in the require statement with require
File.dirname(__FILE__) + '\somefile.rb', which was rather bulky and
inelegant.
I stumbled onto a solution while reading about the array $:. I've hunted
for a solution like this many times, but never found it on Google
anywhere. The solution is this line, affixed to the top of the main
script file:
$: << File.dirname(__FILE__) unless $:.include? File.dirname(__FILE__)
With this, a "require 'somefile.rb'" statement for local files will work
for ANY file linked through all the scripts in the application. My
question is this: why do I not find this method used anywhere? Is there
some staggering disadvantage to doing this that did not occur to me?
Thanks,
Grays